Open Source

Send mail with eSMTP for a simple, single-user system

Vincent Danen introduces you to eSMTP, a lightweight mail "server" solution that also allows per-user configuration files, making it useful even for multi-user systems.

Most Linux distributions install programs like Sendmail or Postfix to handle local mail deliveries. While this works fine on multi-user systems or servers, these programs are quite large and complex for single-user desktop systems. For Linux machines with a single user, the use of more lightweight mail "servers" may be desired: programs like sSMTP or eSMTP. eSMTP allows per-user configuration files unlike other similar programs, and so it's useful even for multi-user systems.

eSMTP is packaged in some distributions so may be easily installed using urpmi, apt, or yum. If not, it is trivial to install although it does require the libESMTP library. If your chosen Linux distribution does not provide a binary copy of eSMTP, download the latest version of libESMTP (1.0.4) and eSMTP (0.6.0) and compile and install them using:

$ tar xvjf libesmtp-1.0.4.tar.bz2
$ cd libesmtp-1.0.4
$ ./configure —prefix=/usr/local
$ make
$ sudo make install
$ cd ..
$ tar xvjf esmtp-0.6.0.tar.bz2
$ cd esmtp-0.6.0
$ ./configure —prefix=/usr/local —with-libesmtp=/usr/local
$ make
$ sudo make install

The resulting libESMTP libraries will be installed in /usr/local, as will the esmtp program. Configuration for esmtp is done via the ~/.esmtprc file.

The ~/.esmtprc configuration file is very straightforward. A very basic one may look like:

hostname = mail.server.com:25
username = "joe"
password = "secret"
starttls = enabled
mda "/usr/bin/procmail -d %T"

This defines the server to which to send mail (the mail hub) — mail.server.com on port 25 with the username "joe" and the password "secret." It also enables the STARTTLS extension. Finally, it defines the local mail delivery agent, procmail.

If you use multiple accounts, you can also tell eSMTP to use multiple SMTP servers dependent upon which account you are sending mail from by using the "identity" keyword:

identity joe@mail.com
    hostname mail.server.com:25
    username "joe"
    password "secret"
    starttls enabled
    default
identity joe@gmail.com
    hostname smtp.gmail.com:587
    username "joe@gmail.com"
    password "secret2"
    starttls required
mda "/usr/bin/procmail -d %T"

eSMTP determines which server to use with the envelope sender flag, which is the -f option to Sendmail and similar MTA's. For mail clients such as Mutt, this can be set with the set envelope_from=yes configuration option. Likewise, the path to Sendmail should be defined as /usr/local/bin/esmtp. For other mail clients, simply telling them to use the local Sendmail and pointing the path to /usr/local/bin/esmtp should be sufficient. If you're unable to define the path to Sendmail, you can also opt to change /usr/lib/sendmail to a symlink pointing to /usr/local/bin/esmtp.

Finally, eSMTP can use the STARTTLS extension, but in order for it to do so, you need to add the root certificate of the CA that signed the server's SSL certificate. eSMTP looks for this information in the ~/.authenticate/ directory. For simplicity, simply download the Mozilla bundle of CA root certificates into this directory; an appropriate bundle suitable for eSMTP can be obtained from the cURL Web site.

$ mkdir ~/.authenticate
$ chmod 0700 ~/.authenticate
$ curl http://curl.haxx.se/ca/cacert.pem >~/.authenticate/ca.pem
$ chmod 0600 ~/.authenticate/ca.pem

With all of this complete, you can use eSMTP to relay mail to an upstream provider SMTP service with ease, without worrying about configuring local Sendmail or Postfix services, which can be especially useful for mail clients with limited or no support for remote SMTP servers.

Get the PDF version of this tip here.

Delivered each Tuesday, TechRepublic's free Linux and Open Source newsletter provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!

About

Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.

Editor's Picks

Free Newsletters, In your Inbox