Introduction
The ssmtp program is designed to be a substitute for sendmail (or postfix, exim and other heavy duty MTA's) for people who need an external smtp program to send mail, such as those who use mutt. While it is slightly more complex and heavy than nbsmtp (no brainer smtp) it is a bit more efficient, writes to /var/log/maillog and has a few nice features.
Do you have ssmtp?
Few systems have ssmtp installed by default, but it never hurts to check. At a command prompt type
which ssmtp
If you get a response like /usr/bin/ssmtp or /usr/local/sbin/ssmtp, you can skip the next step. (Note that some distributions don't include /sbin and /usr/sbin in the $PATH of a user who isn't root. So you might want to log in as root to check if ssmtp is installed.)
Installing
First follow the instructions in the QND software guide for information on getting and installing ssmtp. If it's not included with your distribution then you should be able to download it from ibiblio.
FreeBSD's ports or Gentoo's portage will install ssmtp for you. If you've downloaded the tarball then untar it somewhere and install it in the more or less usual way. This will have to be done as root or with root privilege.
tar -zxvf ssmtp*tar.gz
cd ssmtp*
./configure
make
make install
Configuration
The ssmtp program will install either a sample conf file or the actual file in /usr/etc or perhaps /usr/local/etc, depending upon distribution. This file will have to be edited slightly to make it work. Some of the comments in the file can be a bit misleading. I am including an entire file from a FreeBSD installation, with the hope that it will be clearer where you have to make changes. I am typing in ALLCAPS above the lines that you will have to change.
#
# /etc/ssmtp.conf -- a config file for sSMTP sendmail.
#
# The person who gets all mail for userids < 1000
CHANGE THIS LINE
root=postmaster
# The place where the mail goes. The actual machine name is required
# no MX records are consulted. Commonly mailhosts are named mail.domain.com
# The example will fit if you are in domain.com and your mailhub is so named.
CHANGE THE LINE BELOW
mailhub=mail
# Example for SMTP port number 2525
# mailhub=mail.your.domain:2525
# Example for SMTP port number 25 (Standard/RFC)
# mailhub=mail.your.domain
# Example for SSL encrypted connection
# mailhub=mail.your.domain:465
# Where will the mail seem to come from?
THIS LINE WILL HAVE TO BE EDITED
rewriteDomain=
# The full hostname
THE BELOW LINE WILL HAVE TO BE CHANGED
hostname=
# Set this to never rewrite the "From:" line (unless not given) and to
# use that address in the "from line" of the envelope.
THE LINE BELOW SHOULD BE UNCOMMENTED
#FromLineOverride=YES
# Use SSL/TLS to send secure messages to server.
#UseTLS=YES
# Use SSL/TLS certificate to authenticate against smtp host.
#UseTLSCert=YES
# Use this RSA certificate.
#TLSCert=/usr/local/etc/ssmtp/ssmtp.pem
For our example, we'll assume that your isp is called example.com and their smtp server is smtp.example.com. The local hostname is john.john.com The first line to be changed is
root=postmaster
If you don't change this, and follow the other instructions the postmaster at your ISP might get all mail that would have gone to root. You should change this to your user name with your ISP. For instance, if your user name is john@example.com you can change it to john. If you just use your user name on the machine itself, because of the rewrite domain line that we change below, it might just bounce. I've never tested this actually, I sometimes just put the entire email address in there. If your user name on the machine is john, but your email address is john1@example.com, put in the entire email address. Otherwise, mail going to root will wind up going to john@isp.com, who will not appreciate it. (This is one disadvantage of ssmtp. System messages seem to go through your ISP. As I only use it on a network with an internal mail server, I've never investigated it any further.)
The next line we change is the one that reads
mailhub=mail
In our case, with an smtp server called smtp.example.com it should be changed to read
mailhub=smtp.example.com
Some ISPs require authentication when you are sending mail, as well as receiving it. If they're using SSL I have found it simpler to use msmtp. (See the qnd guide to mutt and gmail.). Other ISPs just want the same user name and password that you use when receiving mail. So, if you have the user name of john and the password of 1234, you can add the following--it doesn't seem to be documented in the man page but it works.
AuthUser=john
AuthPass=1234
The few times I've used this, I simply added those two lines under the mailhub line.
Note that there is a method to do this that is covered in the man page. One can add the -au for authorized user and -ap for password options. If you chose to do it that way, and were using mutt, your .muttrc would have the line
set sendmail=“/usr/local/sbin/ssmtp -au john -ap 1234”
Next, we cover the line that reads rewriteDomain= Using our example of having an isp called example.com it should be changed to read
rewriteDomain=isp.com
In other words, the domain of your isp, eg mindspring.com or whatever. Next, the hostname. The line that reads hostname should be changed to the local hostname.
hostname=john.john.com
The last change to be made is in the line that says FromLineOverride=YES. Many people, (judging from google) including myself, found that line a bit confusing. If you don't uncomment it (by removing the # sign) you may find that all your mail comes from something odd. So, uncomment it. When ssmtp is installed, you will also see a revaliases or revaliases.sample file. The man page only gives it a line or two, as it's relatively simple. If you want an alias for a sending address, configure this file. For example, if you need all mail being sent by root to have the address john@isp.com, you would add this line to your revaliases
root:john@isp.com
You can also specify a mailhub and port in this file if they differ from the smtp server and port in your ssmtp.conf file. For example, in our ssmtp.conf we have smtp.example.com as the mailhub and it's using port 25 (the default.) Suppose that any mail from root goes through a different smtp server and a different port, smtp.example1.com and port 2525. Then, the line would read
root:john@isp.com:mail.exaple1.com:2525
In practice, I've almost never had to make use of the revaliases file, but your needs may be different.
Testing
To test ssmtp, try sending an email. You can send one to yourself, and make sure you get it, or elsewhere. You can also look at /var/log/maillog which should show that the mail was sent successfully.
References
man ssmtp
SSMTP