How can I setup a Mail Transfer Agent?

There are a few choices to be made when selecting an MTA to install; the first one is whether you want a send-only MTA or you need a fully-fledged mail server.

This Unix.SE post provides a comprehensive list of send-only MTAs available; all of them are already packaged for Ubuntu 10.10. There are a few things you might want to consider when choosing a send-only MTA:

  1. whether it can queue e-mails for later delivery in case of a failure: IIRC, only nullmailer can do this.

  2. whether it will replace the system mail delivery agent (look for a line Provides: mail-transport-agent in the output of apt-cache show package). If it does, then all mail originating from the system (including reports from cron jobs, popularity statistics, etc.) will be handled by the MTA you install: if you do not set up correct mail aliases for root and other users, the email might end up delivered at the wrong address (typically, some sysadmin at your ISP). Currently, packages nullmailer, esmtp-run (but not esmtp) and ssmtp fall into this category.

  3. All send-only MTAs will just forward your email to another server (called "relay host" or "smarthost"; typically it's your ISP's SMTP server) and then let it handle all the details of real Internet mail delivery. You need to figure out whether there are any special requirements for connecting to the ISP server (e.g., some kind of authentication or TLS) and choose an MTA that supports the required features (for instance, ssmtp does not support any kind of authentication or SSL/TLS).

Fully-fledged mail servers include exim, postfix, and sendmail. The post-installation installation script for Debian/Ubuntu will do a great job of producing a working configuration for some common setup (delivery of mail to the local system only; sending email through a "smarthost" -- i.e., a mail server you funnel all your emails through, typically your ISP's SMTP host; internet site with full inbound and outbound connectivity). IMHO, postfix is the easiest to run and configure, but since it's so capable, its configuration manual is way longer than any of the send-only MTAs.

In addition, the real risk with setting up a mail server is that, if you make a mistake in the local configuration, you end up with mail delivered to the wrong place (read: lost) or -worse- with an open-relay system that can be used by spammers (and, trust me, they can find an open relay before you realize your server is one).

My advice would be then to start with a send-only MTA and then upgrade to a full mail server only if you see the need for it (which is not the case if you just want to send emails to your GMail address).


I would recommend msmtp. Setting up other mail systems, such as sendmail, is definitely quite a hassle. Once you have msmtp setup, you can use it with mutt, and you can also masquerade it as sendmail so that programs won't know the difference between the two MTAs. Full details available on the website.


The links below provides all the MTA choices you can choose, according to your Ubuntu version:

http://packages.ubuntu.com/precise/mail-transport-agent (for 12.04)
http://packages.ubuntu.com/trusty/mail-transport-agent (for 14.04)

Personally, I found that ssmtp is very easy to setup and run, just 2 commands will do:

$ sudo aptitude install mailutils ssmtp
$ sudo dpkg-reconfigure ssmtp