« Previous 1 2 3
History and use of the mail utility
Magical Mail
Author Caveat
Warning: If you use Gmail as I have done, you should note that your password is kept in plain text within the sSMTP config file. To secure it, you should do the following to allow only root access to that file:
# chown root:mail /etc/ssmtp/ssmtp.conf # chmod 640 /etc/ssmtp/ssmtp.conf
Note the file group mail
in the example may differ from your installation's group.
You can alter your own user group permissions allowing you access with the following,
# usermod -a -G mail chrisbinnie
where obviously chrisbinne
is my username. You then need to log off all of the terminals that you have open to that server. With some trial and error, you can then send a test that works and in that way help protect your plain text password a bit more.
So Many Ss
Although sSMTP is a send-only Sendmail imitator, it has struck a fine balance, again following the Unix philosophy of doing one thing well. That Zen-like balance is one of simplicity and sophistication. It should solve a number of problems in which you cannot or prefer not to install an MTA but still need your outbound mail to behave reliably.
The excellent sSMTP is designed to allow both humans and software to send outbound mail. Besides the ssmtp.conf
file, it is also intelligent enough to listen to a revaliases
file from the same directory. Reverse Aliases
allow a number of users to change their sender email address (their From:
line) automatically.
A common headache for sys admins looking after many servers is that lots of system email is triggered by root@hostname.domainname.tld
. Depending on how you set up your alerting and mail filters, it's sometimes preferable to have the service name as the sender – something along the lines of www3-failover@domainname.tld
or ntp@time.domainname.tld
, for example.
The format for such a file is as follows:
root:mail@cluster42.binnie.tld:external-sysadmins.smtp.tld ntp:stratum-1@ntp.binnie.tld:local-sysadmins.smtp.tld:2525 snort:security@binnie.tld:all-sysadmins.smtp.tld
The optional second element that appears after the first colon is the potentially different SMTP server to punt the mail through; it might be only local or on your LAN, for example. As you can see, you can request port TCP 2525 for localized deliveries, too, or any port for that matter.
On startup, you can pass a few config parameters to sSMTP, such as instructions to ignore all IPv6 addresses with the -4
switch or, conversely, -6
.
Additionally, you can pass a login and password along with the command line (be wary), among other options. It presents quite an old-fashioned shell of sorts. You can trigger it with something like this:
# ssmtp chris@binnie.tld
You can send email after writing that into the command line and hitting Enter with this input format:
To: chrisbinnie@linux.tld From: chris@binnie.tld Subject: Hello, Hello You say goodbye and I say hello
To finish the email, hold down Ctrl+D.
To add an SMTP authentication username to the command line at the start of this process, you just add
-auchrisbinnie -appassword
replacing chrisbinnie
, obviously, with your username and putting -ap
in place before your password.
Again, be wary about passing command-line passwords and be sure that you want to expose your credentials in Bash history or other places. Finally, you can adjust -amCRAM-MD5
or LOGIN
for the authentication scheme in use.
Just like the marvelous mail utility, you can add a debug parameter with the -d2
option, where the number is the level of debugging detail. Mix up your options with a human sender name, such as -fChrisBinnie
. By using the -v
verbose mode, you can see that the mail utility sits very comfortably alongside sSMTP.
Clearly, the outbound MTA needs to fulfill its obligations for the mail utility and sSMTP to function correctly; if you don't monitor your outbound mail servers, then you probably should. With monitoring in place, you will be able to tell why system reports or other email doesn't get sent or received successfully.
End of Transmission
I have reached the EOT signal. In this article, I offered a smattering of history along with some insight into the extensive functionality of the mail utility in its modern form.
Outbound mail is used in almost limitless scenarios, whether it's for backing up tiny logfiles, for the safe-keeping of config files remotely, or for reporting system events – let alone for users to communicate. I hope you now feel suitably proficient with the command line's outbound email idiosyncrasies and feel confident enough to tackle any tricky situations that arise on both ancient, arcane operating systems and modern versions.
« Previous 1 2 3
Buy this article as PDF
(incl. VAT)