/bin/mail has traditionally been a very simple program with which System V Unix users could read a few messages and send a message from the command line. BSD Unix brought a "grown-up" alternative named /usr/ucb/Mail which was a much more powerful tool for message manipulation. Gunnar Ritter wrote nail, now called Heirloom mailx, to augment on mailx' capabilities and he actively maintains it. nail's feature list is very impressive; among others, it supports

  • MIME
  • IMAP (optionally over SSL)
  • POP3
  • SMTP, as well as STARTTLS and SMTPS
  • message threads

Three of nail's features make it my tool of choice for sending messages from the CLI: its support for TLS/SSL, the fact that it can do SMTP authentication (SMTP AUTH), preferably over the former of course, and its support for attachments. Installation is easy and well documented. The program does not use automake, so a simple make will suffice, optionally either editing the Makefile to adjust things or invoking make with parameters. It is a bit unfortunate, that the program has been renamed to mailx as many Unices already have such a tool. I much preferred the name nail, and as such, I install it as nail, if only to avoid invoking the wrong program. Sending attachments from the command line is a snap: the following sends off the specified file (with an empty mail body) to the recipient.

$ nail -a filename \\
       -s 'Here is your attachment' user@example.net < /dev/null

By far the most useful feature for me is being able to send messages securely directly via SMTP without requiring a full-blown local Mail Transfer Agent (MTA) installation such as Exim or sendmail. The following configuration details a setup I use:

set smtp=mail.example.net:587
set smtp-use-starttls
set ssl-no-default-ca
set ssl-ca-file=/etc/chain.pem
set ssl-verify=strict
set smtp-auth-user=user@somewhere.de
set smtp-auth-password=secret

Storing these lines in a ~/.mailrc cause nail to connect to a server at mail.example.net on the given port and perform a STARTTLS dialogue with the server. The server's certificate is verified with the content of the chain.pem file and additionally I perform SMTP-AUTH with the specified set of credentials. If the communication fails with the server, due to incorrect certificate verification or failed credential checking, the message is dumped into ~/dead.letter. Heirloom mailx would be much too rudimentary for me to use as an everyday email client (I use mutt for that), but as a CLI tool for embedding into scripts or programs, nail is the best choice.

Flattr this
Mail, Exim, Linux, IMAP, MacOSX, and CLI :: 08 May 2007 :: e-mail


blog comments powered by Disqus