Set Up Postfix With Mailgun as SMTP Relay

If you ever find that you need to send out email from your server via a relay, as you cannot send them out directly from your server’s IP (eg its been black listed). Relaying the mail via Mailgun is a good option.

To do this you will need to setup your domain in Mailgun, with the free plan you get 50000 email a month free.

Once setup, from the Mailgun dashboard, click on the domain settings link

Finally click on the Reset Password button, and copy the login and password as you will need these when you update your your Postfix configuration.

On your server, now edit the main.cf file:

sudo nano /etc/postfix/main.cf

At the bottom of the file, add the following with your postmaster account and password:

relayhost = smtp.mailgun.org
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = static:[email protected]:yourpassword
smtp_sasl_security_options = noanonymous

Replace:

mg.yourdomain.com with YOUR DOMAIN name
yourpassword with the password you copied from the Mailgun control panel.

Save your changes and restart postfix:

sudo systemctl restart postfix.service

That is the setup completed and Postfix will now relay via Mailgun.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.