Mail on UNIX is weird, I spent a few hours this week tracking down
some bugs in my mail setup, and in the process learnt a lot more about
how things interact. I'm documenting it here for Benno 5 months from
now and anyone else that cares. There is this pseudo-standard of mail
user agents (MUAs) not actually talking SMTP to a mail submission
agent (MSA), but instead simply hoping that
/usr/sbin/sendmail exists. Things are so bound this way
that you really can't avoid having a /usr/sbin/sendmail
on your machine, so as a result other mail transport agents (MTAs)
have to provide a binary that works in the same way as sendmail.
Unfortunately as far as I can tell there is no standard about what
command line flags a sendmail compatible program should accept, and
appears to come down to common usage.
In some ways this is quite backwards to what I would have expected, which is that an MTA would run on the localhost and programs would talk SMTP to port 25 (or the MSA port 587), then all communications is through this documented standard. On the other hand, this means every program that wants to send e-mail must have TCP and SMTP libraries compiled which is against the UNIX philosophy.
Now I am actually quite interested to find out what other programs (that I use), actually rely on sendmail. I'm guessing (hoping) that it is mostly just MUAs such as mutt and mailx, but I really wonder what else is out there relying on sendmail.
More importantly, what command lines arguments do these different
programs expect /usr/sbin/sendmail to handle correctly.
(In case I wanted to join the hundreds of others and say, write my own
sendmail replacement). So after putting in a simple python program to
log the command line arguments my great findings are:
mailx uses the -i argument. This one is
great, by default a line with a single '.' character is treated as the
end of input, with the argument standard end of file, means end of
file. mutt on the other hand uses -oi
(which is the same as -i, and
-oem. -oem is conveniently undocumented in
Postifx's sendmail man page, but on consulting the exim sendmail man
page, discovered that this basically means, the command can't fail,
and any errors should be reported through email, rather than with an
error return code.
mutt lets you override the command it uses for mail submission by
setting the sendmail variable. This is handy to know if you
want to add extra arguments to the sendmail command line. For example
a handy feature is being able to control the envelope from address
used. This is done with the -f command line argument.
Next up for my adventures in the wonderful world of UNIX email
is to setup my on sendmail compatible program, that can set the
envelope address and smarthost to use based on the e-mail From:
header.