Back to main page

The Quick-N-Dirty Guide to ssmtp

The aim of this QND guide is to get you up and running quickly with ssmtp. There will be far more how than why here.

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. It will not, however, be a complete substitute.

I should add, that ssmtp has been abandoned. That means that no one really maintains it anymore. ArchLinux, for example, has removed it from its main repositories, though it's still available from their AUR packages. These days, I recommend msmtp. Although we don't have a qnd msmtp page, we do cover setting it up on our gmail page.

1.) Do you have ssmtp?

I don't know of any Linux distro or other *nix system that installs ssmtp by default. However, it never hurts to check. At a command line type
which ssmtp

If you get a response like /usr/bin/ssmtp or /usr/local/sbin/ssmtp, you can skip to step 3. Otherwise, continue with step 2.

2.)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 (while it is in Gentoo's portage and FreeBSD's ports, it doesn't seem to be on any of the RedHat 8.0 CD's) then it can be gotten from Debian's site. They have a tar.gz file, ssmtp_2.61.orig.tar.gz.

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
If you are going to use it to completely replace your system's sendmail program, FreeBSD includes a little script make replace. While in /usr/ports/mail/ssmtp type
make replace

It will then edit /etc/mailer.conf for you, replacing the defalt sendmail with ssmtp. In RedHat based systems you can use
alternatives --config mta 

This will open a dialog enabling you to replace sendmail with ssmtp.

3.)Configuring ssmtp

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 isp.com and their smtp server is smtp.isp.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@isp.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@isp.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.isp.com it should be changed to read

mailhub=smtp.isp.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 isp.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 User &. 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 ssmtp/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.isp.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.isp1.com and port 2525. Then, the line would read
root:john@isp.com:mail.isp1.com:2525

In practice, I've almost never had to make use of the revaliases file, but your needs may be different.

4.) Testing ssmtp

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.

One can use ssmtp to just send system messages as well, rather than run sendmail or postfix to do nothing more than simple internal messages. In such a case, change the mailhub= line in ssmtp.conf to localhost. Note that this means you can't use it for anything else. In other words, you have the choice of setting it to the localhost or to your ISP's mailserver, but not both, as far as I know.

Once again, you would have to configure your system to use ssmtp rather than its default of sendmail or whatever.

References

man ssmtp

Back to main page