I believe that mailx is something else -- Ubuntu Intrepid has both mailx and nail -- but I don't know what the differences are. The main reason I was using nail was that at some point a few years ago I found a fairly clear, simple explanation of how to use nail + msmtp to send simple emails from the command line. In general, the documentation for the various MUAs and MTAs seem overwhelmingly complicated and poorly explained. It's amazing how simple this turns out to be.
Anyway, I had already installed smail (and uucp) and uninstalled exim4. The man pages for smail were just as bewildering as the others -- that's why I was looking for nail. (Apparently the mail command is provided by either mailx or smail, because after I had this all working, I uninstalled both mailx and smail -- and tried to send an email but got an error -- bash: /usr/bin/mail: No such file or directory -- so I reinstalled smail, uucp and mailx.)
But thanks for your suggestion to use the mail command -- it may seem obvious to you but to the uninitiated it's anything but obvious. That turns out to be the easy solution & I guess mailx, smail and nail are all unnecessary for this simple application. The manpage for msmtp actually tells how to write both configuration files.
For anyone else struggling with this (and for me next time I forget how to do it), here is a summary. This is, I believe, the minimum necessary for barebones functionality, which is probably enough for many applications.
-------------------------------------------------------------------------
USING MAIL + MSMTP TO SEND EMAILS FROM A TERMINAL PROMPT OR FROM A SCRIPT:
-------------------------------------------------------------------------
mail (/usr/bin/mail) is provided by mailx or smail (smail requires mailx and uucp), and msmtp provides the interface to the isp that forwards the mail. So:
~$ sudo apt-get install msmtp smail uucp
(mailx will be installed as a dependency)
In your home directory, create a ~/.mailrc file containing just:
Code:
set sendmail=/usr/bin/msmtp
Create a config file for msmtp; mine is ~/.msmtprc but I think a systemwide /etc/msmtprc file would work as well. For my Verizon account this file consists of:
Code:
# .msmtprc ##configuration file for msmtp
#account verizon
host outgoing.verizon.net
from [from address to appear on the email]
auth login
tls off
user [username]@verizon.net
password [************]
#account default : verizon
notes:
- The lines "account verizon" and "account default : verizon" are commented out -- they seem to be unnecessary if only 1 account is listed in the file.
- The [from address ...] can be whatever you want to appear on the email; it does not have to be your isp account address.
- The line "auth login" is to be copied exactly. This "login" is NOT your username.
- You'll have to determine the appropriate entries for the host, auth, and tls lines, depending on your isp.
To send an email manually from a terminal prompt, type a first line consisting of the command, the subject and one or more recipient addresses (no commas):
Code:
~$ mail -s "the subject line" [first recipient] [second recipient] [...]
followed by <enter>.
Then type the body of the message. This can be on multiple lines (<enter> will not terminate the message).
Finally, to terminate the message, type <enter> at the end of the last message line, and then type ctrl-D at the beginning of the next line.
To send an email from, say, a perl script, include a line similar to this in the script:
Code:
system("echo \"Body of the message\" | mail -s \"Subject line\" recipient1@address1 recipient2@address2");