Email – How to Setup a Mail Transfer Agent

cron-jobsemail

I intend to use mutt to send automated emails via cron or at with attachments to my gmail address when particular events happen on my Ubuntu server. Currently, mutt cannot send email to external email addresses, I believe this is because I need to setup a Mail Transfer Agent. How do I go about selecting a suitable MTA and how do I set it up to perform what I need it to do?

Best Answer

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).

Related Question