Linux

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.

10 comments
kellyjackie
kellyjackie

I followed all of the instructions. how do i test the email is working?

critch
critch

In my experience, this is "Feed a man a fish, you have fed him for a day; Teach a man, you have fed him for the rest of his life"... There are WAY too many people in IT who do not understand the basics.. a command line, enviromental settings, etc. Am I a bigot? Probably.. "real operating systems have a command line".. I spend probably half of debugging/troubleshooting from a command window... I use Windows, I use Linux, I like AIX... but I understand How they work, not what icon to click /*end of rant*/

dgs010243
dgs010243

Hello, It is a hot summer ! The number of comments decreased. Let's use extended SMTP with a condition: please implement it ! http://dan.somnea.free.fr/2C/prolinux.php Dan Gheorghe PS my linux is unnoperational due to this hot summer !

roger
roger

Linux is a pain in the command line arse. "Easy to install, but"... then a list of crap you have to find and install. Not ready for prime time yet, by a long way. Here is what they have to do: Linux has to be better and easier than Windows. It has to attract users not look for users escaping from the clutches of MS. It will always be easier to tolerate Windows a little longer than switch to Linux as both make slight improvements over time. It's got to be BETTER and EASIER than Windows. Listen!

apotheon
apotheon

Yes, I'm a little late to the party here, but this has to be said: Most of that crap in the article isn't necessary for most users of systems that support eSMTP. I'm always annoyed when someone writes an article -- in this day and age, even -- wherein they talk about how easy it is to set something up on a Unix-like system, then spend half the article doing it in the most difficult manner possible. The way eSMTP's installation is described in this article is called "installing from a source tarball". It's the kind of thing you do when something is new or unknown enough that nobody has incorporated it into a proper software management system. It's now developers install software for testing while they're developing it. It's not how you should be installing eSMTP yourself. Forget all that "tar, make, configure, sudo" crap. (. . . which reminds me -- I'm always annoyed by this increasingly prevalent assumption than everyone in the world uses sudo for everything, too.) Each of the following examples requires root access (via the sudo command, using su, or just logging in as root at a VT, as appropriate). On Debian GNU/Linux, enter [b]apt-get install esmtp[/b]. On FreeBSD, enter [b]portinstall esmtp[/b], [b]pkg_add -r esmtp[/b], or [b]cd /usr/ports/mail/esmtp; make install clean[/b], depending on your preferred means of installing software (yes, you have several very easy options). On Fedora Core Linux, enter [b]YUM install esmtp[/b]. Pretty simple. Much easier than the equivalent for something like MS Exchange. Easier even than installing your average email client application on MS Windows. So . . . if you don't know anything about how software is installed on an OS like Linux, don't just assume that the way some article describes it is the easiest way to do it, and use that as an excuse to go around badmouthing what you don't understand.

don
don

Just because you are not intelligent enough to see how simple it is, do not insult what you do not understand.

zloeber
zloeber

If all you know is windows and cannot learn anything else that is different then nothing will satiate your irrational needs. No one is trying to sell you anything, why are you acting like a wanted customer? For what it is worth, I use both without prejudice.

Ajax4Hire
Ajax4Hire

I see your lips moving but all I hear is oh-waaaa.

Dumphrey
Dumphrey

Set up a full Qmail, or exchange system, and this ill seem refreshing. But, I will give you even though its trivial by comparison to a full blown server, it is still not "double-click simple", you cant simply be a utility user and do this with out a lot of reading.