The /usr/bin/mail program on *nix

Jeremy Portzer jeremyp at pobox.com
Mon Nov 24 09:59:59 EST 2003


Hey folks,

Joseph Mack and Joseph Moran recently had a conversation about MTAs; I
forgot to check my NC*SA folder and didn't see it until now.

Anyway, I wanted to point something out about the /usr/bin/mail program,
sometimes referred to as "mailx."  I believe the operation of this
program has been misunderstood.

This program is not an MTA.  It does not deliver to recipients at all. 
Instead, it invokes the "Unix movemail" facility, namely
/usr/sbin/sendmail.  This same facility can be invoked from pine or from
Netscape and Mozilla Mail.  (I'm not sure that Evolution supports it
though.)

When you send a message via "mail", you are just passing the message on
to the local MTA, which is invoked as /usr/sbin/sendmail (or more
traditionally, /usr/lib/sendmail), regardless of which MTA is actually
installed (qmail, postfix, etc. put a symlink or compatibility binary at
that location).  Delivery of the message is contigent upon the local MTA
being configured correctly.  The local MTA may then deliver the message
to the recipients itself, or it may pass it onto a relay server ("Smart
host" in sendmail).

If you're running Windows, there is little concept of a local MTA, so
you have to install programs like "Windmail" that accept mail from
standard input, and then forward them to an SMTP relay server.   The
"mail" program itself has no understanding or support for SMTP.

You can verify this by on Linux by running "strace" on a mail process,
or by looking at the source code.  For example:

$ strace -f /usr/bin/mail jeremy 
(inputted a test e-mail)
The strace output will show it copying the information to a temporary
file, then running this:
execve("/usr/sbin/sendmail", ["send-mail", "-i", "jeremy"], [/* 32 vars
*/]) = 0uname({sys="Linux", node="jeremy.example.com", ...}) = 0

For an example of the source code that provides this facility, see
http://www.freebsd.org/cgi/cvsweb.cgi/src/usr.bin/mail/send.c and
download the latest version -- look at the mail1() function.  Sending
mail is as simple as execve()'ing sendmail. There are no sockets or
network connectivity involved.

You can also run /usr/bin/sendmail from the command-line, or from a
script, with the "-t" option.  This is a quick way to send mail from
scripts that gives you more flexibility than calling the "mail" binary,
because you can put whatever headers you need.  The -t option tells
sendmail to extract the envelope sender and recipient from the headers
you provide.  See the documentation.

Hope this helps,
Jeremy

-- 
/---------------------------------------------------------------------\
| Jeremy Portzer        jeremyp at pobox.com      trilug.org/~jeremy     |
| GPG Fingerprint: 712D 77C7 AB2D 2130 989F  E135 6F9F F7BC CC1A 7B92 |
\---------------------------------------------------------------------/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://www.ncsysadmin.org/pipermail/ncsa-discussion/attachments/20031124/b4e8abd4/attachment.bin


More information about the ncsa-discussion mailing list