February 20, 2016

Postfix Smarthost with Debian Jessie

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. I have previously written this guide for Ubuntu Here, its very similar on Debian 8 but there are some differences:

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 postfix edit the file in nano: nano /etc/postfix/main.cf
  • Add the following lines to the main.cf file:

smtp_sasl_auth_enable = yes

relayhost = [smtp.mailgun.org]:587

smtp_sasl_security_options = noanonymous


  • Create the sasl__passwd file in nano: sudo nano /etc/postfix/sasl_passwd
  • Enter the following line: [smtp.mailgun.org]:587 username@domain.com:secretpassword
  • 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: box.howson.me then add this as a custom domain to mailgun. If some mail is sent as root@howson.me 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