Install Postfix Email Server

Postfix is a mail transfer agent that enables sending email from Drupal. This is required, for example, to enable Drupal-based contact forms and user registration confirmation messages. We will assume that you have already correctly configured MX records in DNS.  The following instructions cover the minimum required to send email from Drupal.

Email, however, is a relatively complicated beast and we highly recommend reviewing the Postfix section of the Ubuntu Server Guide before you proceed. Mistakes here can open your server up to be used as a spam relay and may even get you blacklisted. A little reading now can save you some major pain later.

Install Postfix non-interactively:

sudo DEBIAN_FRONTEND=noninteractive apt-get -y install postfix

Optionally, you may wish to install mailutils, a handy batch of email utilities that can help with testing and configuration:

sudo apt-get -y install mailutils

Set the default domain from where mail will originate and (optionally) any virtual domains:

echo "example.com" | sudo tee /etc/postfix/mailname
echo "example2.com my-alias" | sudo tee /etc/postfix/virtual

Create the Postfix main.cf configuration file, set the mail origin to /etc/mailname and (optionally) set the virtualhosts file and mail relay:

echo 'myorigin = /etc/postfix/mailname
virtual_alias_maps = hash:/etc/postfix/virtual
relayhost =' | sudo tee /etc/postfix/main.cf

Reload postfix to enable the configuration changes and refresh the virtual mappings:

sudo /etc/init.d/postfix reload
sudo postmap /etc/postfix/virtual

Find an error? Know a better way? Please leave a comment and help improve this cookbook.