November 8, 2015

Using Mailgun to send System Mail in Ubuntu 14.04 LTS

After running a mail server for a number of years I got fed up of managing spam and unreliable delivery for system mail. Expanding my recent of use mailgun for web applications I have now set it up to handle system mail. There was not a great deal on there on doing it with Ubuntu so here is a concise guide:

For simplicity I will assume you don't have an existing mailserver. If you do it may be easier to remove it using the purge option and start again.

  • Install the mail server by running: apt-get install postfix libsasl2-modules
  • Now you need to configure post fix edit the file in nano: sudo nano /etc/postfix/
  • Add the following lines to the file:

smtp_sasl_auth_enable = yes relayhost = smtp_sasl_security_options = noanonymous smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd

  • Create the sasl__passwd file in nano: sudo nano /etc/postfix/sasl_passwd
  • Enter the following line:
  • Set the permissions for the sasl_passwd file:

    sudo chmod 600 /etc/postfix/sasl_passwd
  • Postmap the file: sudo postmap /etc/postfix/sasl_passwd
  • Restart postfix sudo service postfix restart

Finished! A easy way of routing all your system mail through postfix. You will need to ensure you have added your custom domain into mailgun. For example if your server is called: then add this as a custom domain to mailgun. If some mail is sent as from the server don't worry this configuration will still work and is simple as it does not interfere with the mail provider serving your domain. Even DKIM and SPF work without any changes.

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket
Comments powered by Disqus