23

Whats the difference between mail and mailx?

I'm trying to troubleshoot a problem where I can send mail from server A with this echo $MESSAGE | mail -s "$SUBJECT" -r $FROM $RECIPIENTS command but executing the same command from server B throws me this error (Both servers are RHEL)

mail: invalid option -- r
Usage: mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...
            [-- sendmail-options ...]
       mail [-iInNv] -f [name]
       mail [-iInNv] [-u user]

Now... going through mail manpages to ty to understand whats happening, man mail gives me this:

In Server A

MAILX(1)                         User Commands                        MAILX(1)

NAME
       mailx - send and receive Internet mail

SYNOPSIS
       mailx [-BDdEFintv~] [-s subject] [-a attachment ] [-c cc-addr] [-b bcc-addr] [-r from-addr] [-h hops]
              [-A account] [-S variable[=value]] to-addr . . .
       mailx [-BDdeEHiInNRv~] [-T name] [-A account] [-S variable[=value]] -f [name]
       mailx [-BDdeEinNRv~] [-A account] [-S variable[=value]] [-u user]

But in server B

MAIL(1)                   BSD General Commands Manual                  MAIL(1)

NAME
     mail - send and receive mail

SYNOPSIS
     mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr... [-- sendmail-options...]
     mail [-iInNv] -f [name]
     mail [-iInNv] [-u user]

Now... if I try man mailx in server B I get:

MAILX(P)                   POSIX Programmerâs Manual                  MAILX(P)

PROLOG
       This manual page is part of the POSIX Programmerâs Manual.  The Linux implementation of this interface may differ
       (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not  be  imple-
       mented on Linux.

NAME
       mailx - process messages

SYNOPSIS
   Send Mode
              mailx [-s subject] address...

   Receive Mode
              mailx -e

              mailx [-HiNn][-F][-u user]

              mailx -f[-HiNn][-F][file]

Server B has a different version of mail than Server A? Mailx and Mail are different things? I would like to use the -r option I use in server A but in server B and I don't really know whats happening.

AnFi
  • 1,546
Rhyuk
  • 1,115

1 Answers1

23

Behold the confusing history of mail, nail, mailx.

Briefly, mail is the older program, mailx (formerly nail in some implementations) is a newer version , with an extended mostly-but-not-totally-compatible interface.

mailx is still quite old, created around 1986 and standarized as part of POSIX in 1992. There are several implementations (even in modern Linuxes), and some provide extensions to the standard.

The -r option is one such extension. Depending on your Linux distribution, and the mail package you have installed, you might or not have that option. See eg here.

If you want to write portable scripts, it's better not to rely on it.

leonbloy
  • 448