This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new!

Feature: Mail & Messaging

sSMTP: A simple alternative to Sendmail

By Michael J. Hammel on April 18, 2008 (9:00:00 AM)

Share    Print    Comments   

Linux distributions have relied on the venerable Sendmail package since the early days of Slackware. But Sendmail's rich mail server features aren't an ideal solution for the typical desktop user whose primary mail support is delivered through a remote ISP. That's the perfect place for a simpler solution: sSMTP.

Many years ago, before the Internet standardized on Simple Mail Transfer Protocol (SMTP), applications known as mail transfer agents (MTA) were designed to help process email and determine the best route for message delivery. One of the earliest MTAs, Sendmail, became extremely popular for dealing with the delivery of email across multiple networks. It was the only viable open source mechanism for delivering email at the time Linux was introduced to the world, so it became the default MTA provided on many Linux distributions.

There has always been a division of labor for email processing. MTAs handle delivery of email and mail user agents (MUA) such as GNOME's Evolution, KDE's KMail, and Mozilla Thunderbird let users create and manage messages. MUAs have only a very basic concept of how to deliver mail. They don't need to know how to send a message to its intended recipient; they know only about delivering mail to a specific generally server-based MTA, which is then responsible for routing email to the ultimate recipient.

If you run cron jobs or some automated system that sends you alerts via email, the default method the system uses for sending the message is Sendmail, because it is the default MTA for the built-in Linux mail command (typically /bin/mail). This means you not only have to configure your mail reader to send email to your ISP, but you also need to configure Sendmail to do the same thing.

Unfortunately, Sendmail configuration is a mass of twisty passages that even the most experienced user avoids if at all possible. That means it is not the best tool for the typical desktop user.

Two popular Sendmail MTA alternatives, QMail and Postfix, started off simple, but have become complex systems on their own, with capabilities far beyond the needs of a typical desktop user who seeks to simply route email from his machine to his ISP. Alternatively, you could choose a tool other than /bin/mail to send email through direct use of SMTP, such as elm or pine, but these are full MUA clients that provide lots of options that are overkill for addressing the primary problem of mail delivery to an ISP.

The simplified solution: sSMTP

Instead of finding a complicated replacement for mail, you can replace the complicated Sendmail with a simple alternative: sSMTP. sSMTP simplifies configuring your SMTP options with a small configuration file that allows you to specify items like the name of the remote SMTP server, your authorization (username and password), and the domain for your outbound email in much the way you configure your mail reader.

You can install sSMTP through your distribution's package manager, or build and install it from source. In the latter case, unpack the source, change into the source directory, and run the command ./configure --prefix=/usr/local/ssmtp --enable-ssl --enable-md5auth. Enabling SSL and MD5Auth allows you to communicate with an ISP that requires SMTP login. You can also enable IPv6 support if you need it; see --help for details.

After the configuration is complete, build and install the package using the normal make and sudo make install commands. When you run the install command you will be prompted for a few items. Follow the displayed instructions. Once installation completes you should find a directory called /usr/local/ssmtp with the sSMTP binary under the sbin subdirectory, and the configuration file under the etc/ssmtp subdirectory.

Now you can stop Sendmail and replace it with sSMTP. To stop Sendmail under Linux distributions that use the System V init scripts (and most distributions these days do) you can try the service command:

sudo service sendmail stop sudo chkconfig --levels 2345 sendmail off

The first command stops the currently running instance of Sendmail, and the second prevents it from starting again on reboots. If your version of Linux does not use the SysVInit package you may need to kill the sendmail process manually with a command like sudo killall sendmail.

To replace Sendmail you can simply copy it to another file, then create a symbolic link from sSMTP to sendmail:

sudo mv /usr/sbin/sendmail /usr/sbin/sendmail.orig sudo ln -s /usr/local/ssmtp/sbin/ssmtp /usr/sbin/sendmail

The first command moves the original sendmail out of the way, while the second makes sSMTP the program that gets run when any system command calls sendmail. With this approach, if you run into problems using sSMTP, just remove the symbolic link and move the sendmail copy back to its original name.


The configuration file for sSMTP, based on the --prefix option we used with the configure command while building from the source code, is /usr/local/ssmtp/etc/ssmtp/ssmtp.conf. This file has only four common options, plus some hidden options for authentication.

After a sample build, sSMTP created the following configuration file for me (lines starting with a # symbol are comments):

# /etc/ssmtp.conf -- a config file for sSMTP sendmail. # # The person who gets all mail for userids < 1000 # Make this empty to disable rewriting. root=postmaster # The place where the mail goes. The actual machine name is required # no MX records are consulted. Commonly mailhosts are named # The example will fit if you are in and you mailhub is so named. mailhub=mail # Where will the mail seem to come from? # The full hostname

Change the root= value to an email address that will receive all system-generated email, such as output from cron jobs that encounter errors or log file analysis. I changed this line to my personal email address.

mailhub= defines the SMTP server to which email should be sent. Set this line to the host you specify in your mail reader for the SMTP server.

hostname= is the name of the mail host that you'd like recipients of your email to see it. Since I want responses to my email to be sent to back to my ISP domain so I can use my mail reader to retrieve it, I set this line to the ISP domain. This is the domain part of all outbound messages; all users on your system will appear to be coming from this domain.

You can use rewriteDomain= to spoof who you say you are. Since I'm already spoofing the server address with the hostname line, I leave this line commented out.

The initial configuration does not include information on how to log in to SMTP servers that require authentication. This information is the same information you must provide in your mail reader in order for it to send email through your ISP. To specify this information, you can add the following lines:

AuthUser=your username AuthPass=your password AuthMethod=CRAM-MD5

With this configuration, every time my system sends mail using /bin/mail, sendmail gets called, which is actually sSMTP. sSMTP uses the authentication I provided in the configuration file to log in to my ISP's SMTP server and deliver my outgoing email.


Replacing Sendmail with sSMTP works well for desktop PCs that have only a single user configured. If you have multiple users, you may not want to use sSMTP, since by default all email sent via the mail command will look like it comes from a single user. An additional configuration file, revaliases, allows you to map a local user to a specific From: address on outbound mail and to route that mail through a specific mailhub. Still, there is no way to configure different logins on different mailhubs that use different different authentication credentials. With sSMTP, your outbound mail can only have one remote MTA to which it can connect.

Also, in order for any user on your system to use sSMTP, they will need to have read permissions on the ssmtp.conf file. Placing your ISP login information in a configuration file that is world-readable allows anyone who uses your system to see your email authentication information. This is another reason why use of sSMTP is appropriate only for home users who are the sole users of that system. You can fix this problem through normal user and group permissions and by running sSMTP as a setuid program, but not if you want to make things as simple as possible, as we set out to do.

While sSMTP is a replacement for Sendmail, it is not a complete replacement. One important distinction is that it is not intended to receive mail, as Sendmail does. You need to use a mail reader to retrieve and read email from your ISP.

sSMTP also does not manage mail queues, so it sends outbound email immediately. Although the man page for sSMTP shows support for all the same command-line options that Sendmail supports, sSMTP ignores most of those options.

Finally, the sSMTP implementation enforces a limit on the size of outbound message headers. Try not to write long subject lines or include long lists of recipients. If you need to send something to a large list of recipients, set up an alias instead of manually listing all the recipients on the command line.

sSMTP is exactly as advertised: simple. It requires only minimal effort to set up and little to no long-term maintenance. But it isn't appropriate for all users. Its greatest value is to the non-technical home user with only one user configured on a machine. To those users, sSMTP can be an easy way to improve messaging management.

Michael J. Hammel is a principal software engineer for Colorado Engineering, Inc. (CEI) in Colorado Springs, Colo. He has more than 20 years of software development and management experience, and has written more than 100 articles for numerous online and print magazines. He is the author of multiple open source related texts, including three books on the GIMP.

Share    Print    Comments   


on sSMTP: A simple alternative to Sendmail

Note: Comments are owned by the poster. We are not responsible for their content.

Yet ANOTHER replacement for sendmail! Why??

Posted by: Anonymous [ip:] on April 18, 2008 10:06 AM
There must be about a dozen wannabe "replacement for sendmail" programs now. I use Exim, a lot of people use qmail, or postfix, or MXM, or ... I can't be bothered to google for all of them. Why oh why do people waste their time re-inventing the wheel? It's not only a waste ot time; by fragmenting the user base, it means that a lot of these wannabes never build up enough of a user base to get really thoroughly tested.

And - when some clown decides to reinvent the wheel - why does have to write about it?


Re: Yet ANOTHER replacement for sendmail! Why??

Posted by: Anonymous [ip:] on April 18, 2008 10:24 AM
"And - when some clown decides to reinvent the wheel - why does have to write about it?"

Because some people actually like to have alternatives. I found the article interesting.


local only MTA?

Posted by: Anonymous [ip:] on April 18, 2008 12:03 PM
What if i need a (light) mta for mails from cron jobs only?

What do you use?


sSMTP: A simple alternative to Sendmail

Posted by: Anonymous [ip: unknown] on April 18, 2008 12:10 PM
It's not re-inventing the wheel. More like upgrading from stock to Jet Alloys with Firestone F700's.


sSMTP: A simple alternative to Sendmail

Posted by: Anonymous [ip:] on April 18, 2008 12:59 PM
I think that all of the replacements you mentioned would resent being labeled as a light weight replacement. sSMTP is not intended for server use but for desktop/single user.

So before you criticise; please spend a second to think.


sSMTP: A simple alternative to Sendmail

Posted by: Anonymous [ip:] on April 18, 2008 01:38 PM
I don't think this is really a sendmail replacement. Exim, postfix, qmail all of those are. This is a just a way to forward your local mail to another smtp server. I use it for all of my inside boxes and just point it to my smtp server. Then all my mail filters through one box.


Re: sSMTP: A simple alternative to Sendmail

Posted by: Anonymous [ip:] on April 18, 2008 03:41 PM
I think that you should read the article completly before posting any comment.


sSMTP: A simple alternative to Sendmail

Posted by: Anonymous [ip:] on April 18, 2008 02:32 PM
What I'd like to know is which of the group is smaller (Exim, portfix, qmail, ssmtp, etc.) so I can use them on embedded systems which need to send out mail to a user. Also, how well does it work with secure ports on services like Google mail?

Embedded systems need lightweight and small, they're not sending tons of mail and only to a very limited group of users.


sSMTP: A simple alternative to Sendmail

Posted by: Anonymous [ip:] on April 18, 2008 05:45 PM
I've used eSMTP for years as a light-weight MTA and found it to fit my needs to a "T."


sSMTP: A simple alternative to Sendmail

Posted by: Anonymous [ip:] on April 18, 2008 11:26 PM
Hardly a sendmail replacement when its designed for use on desktop machines by single users.

To quote the author:

"Replacing Sendmail with sSMTP works well for desktop PCs that have only a single user configured. If you have multiple users, you may not want to use sSMTP"

Yeah. Good one, idiot.

Anything touted as a sendmail replacement needs to support things like advanced mail routing and rewriting, ssl, tls, and sasl, for a start.



sSMTP: A simple alternative to Sendmail

Posted by: Anonymous [ip:] on April 18, 2008 11:38 PM
s/Two popular Sendmail MTA alternatives, QMail and Postfix,/Three popular Sendmail MTA alternatives, QMail, Exim and Postfix,/


sSMTP: A simple alternative to Sendmail

Posted by: Anonymous [ip:] on April 21, 2008 05:54 PM
Hang on guys - name calling isn't required.

For 99% of the machines out there, all they do is forward all mail to a mailhub. The mailhub is the one that has to do all the mail routing/rewriting/ssl, tls, etc... I believe the author is suggesting that for the majority of users, replacing the "sendmail executable" with the ssmtp executable on these typical machines would work for the majority of people.

I agree. And the other caveats are noted in this article.

I like it. Thanks, Michael!


sSMTP: A simple alternative to Sendmail

Posted by: Anonymous [ip:] on April 25, 2008 08:23 AM
Another simple alternative to check out is mSMTP .. pretty much ssmtp without the bugs and with a few additional useful features.


This story has been archived. Comments can no longer be posted.

Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya