(or how the “/usr/(s)bin/sendmail” issue was solved )
It was random that I have found a page which mentions to send an email via smtp using mailx. I was really surprised because I didn't know that. After some investigation I found that there was a forked and extended version of the traditional mailx - Heirloom mailx, formerly called nail.
Beside other functionality I will have a look at the side of sending mails only. So the traditional mailx works in a way that it checks $PATH for
sendmail  and if it was found it hands over the mail for further processing. The benefit to call
mail  instead of
sendmail  directly was the usage in portable scripts. Before we going on lets have a look at the
Short: It is not possible to install more than one MTA at the same system at the same time!
Ok, ok - I know. There are workarounds to do so. But I talk about a standard and default installation using the system's package manager. And the package management tool HAVE TO prevent this. Even if there could happen multiple issues with multiple MTA's I want to stay with the
/usr/bin/sendmail  issue here. Beware that this typical location does differ between UNIX'like systems. But usually the location is the same of a dedicated system always.
Every MTA has its own
sendmail  binary to be compatible to the users interface side - more or less. But these binaries are not exchangeable between different MTA's. Thus you have one location for
sendmail , thus you have to have one
sendmail  tool and thus you have to have one MTA installed at a time. Point. That's why package managers works like described above.
Sidestep: In the past there does exist a tool called sendmail-wrapper or alike, but it seems it is not wide spread in use anymore.
As the traditional UNIX
mail  command uses
sendmail  it is required to have a local MTA installed. With Heirloom mailx this is no longer required. Through smtp we can send mails to every remote MTA inside or outside a local network.
The following code snippet shows how it could be used:
SENDMAIL=`which mail 2>/dev/null` SENDER="admin@`hostname`.example.org" SERVER="smtp=smtp://smtp.example.org" SUBJ="Message from `hostname`" # subject BODY="`hostname`: I did my job succesful." # log an error and exit if 'mailx' isn't available [ ! "$SENDMAIL" ] && echo "`date` `basename $0`: couldn't find '(send)mail'" \ >> /var/log/messages && exit 1 # send a mail - this is a bit different against sendmail # Attention: do NOT quote the options itself, only their values! "$SENDMAIL" -s "$SUBJ" -r "$SENDER" -S "$SERVER" email@example.com << EOF "$BODY" EOF
As of its nature mailx doesn't spool a mail. Thus, by connecting via smtp , it have to made sure that the receiving mail server (mta) accepts the mail immediately. So for example if the receiving mta has grey-listing activated, the server running mailx have to be white listed. But is this a caveat?
To me Heirloom mailx is one of best innovations for UNIX'like systems. With its backwards compatibility it is a full replacement for the old, outdated Berkeley mailx. And as more systems an administrator have to maintain as higher is the benefit. I'm really impressed