Setup Postfix with Mailgun for Reliable Email Delivery on Ubuntu

Setup Postfix with Mailgun on Ubuntu – Pheonix Solutions featured image showing Postfix SMTP relay and Mailgun email delivery.

Post Date: 02 September 2020
Last Updated: 16 November 2026

Introduction

Setup Postfix with Mailgun on Ubuntu to configure email delivery through Mailgun as an SMTP relay. Postfix is a Mail Transfer Agent (MTA) responsible for delivering and receiving emails. It is essential for creating a complete mail server.

In this guide, we will explain how to install Postfix, create a Mailgun account, and configure Postfix to send emails through Mailgun.

Implementation Steps

Step 1: Install Postfix

Log in to the server using SSH.

As the root user, install Postfix using the following command:

apt-get install postfix
Setup Postfix with Mailgun on Ubuntu – Postfix installation configuration screen.

Now, enter the fully qualified domain name (FQDN) that you want to use for sending and receiving emails.

Postfix Mailgun Configuration – Postfix setup screen displaying the fully qualified mail domain.

Once the FQDN is configured, restart the Postfix mail server using the following command:

service postfix restart

Step 2: Sign Up for a Free Mailgun Account

Mailgun provides powerful APIs that allow you to send, receive, and track emails.

Sign up for a Mailgun account using the following link:

https://www.mailgun.com

Once you have signed up, access your Mailgun Control Panel:

https://mailgun.com/cp

Follow these steps to add your domain:

  1. Click the Domains tab.
  2. Select the Add Domain button.
  3. Enter your domain name.
  4. Click the Create Domain button at the bottom of the form.

This will create your domain in Mailgun.

Click the Domains tab again and select your newly created domain from the list. This will open the details page for your domain.

Step 3: Configure Postfix to Use Mailgun as a Relay Host

You can find your SMTP password on the domain details page in Mailgun. This password is required when configuring Postfix to send emails through Mailgun.

Edit the Postfix main.cf file using the following command:

nano /etc/postfix/main.cf

Add the following configuration at the bottom of the file:

relayhost = smtp.mailgun.org
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = static:postmaster@pheonixsolutions.com:password
smtp_sasl_security_options = noanonymous

Replace the following values:

  • pheonixsolutions.com with your domain name.
  • password with the password obtained from the Mailgun Control Panel.

Save your changes and restart Postfix:

service postfix restart

Your Postfix server will now send emails through Mailgun.

Conclusion

Postfix can be configured with Mailgun to send emails through an external relay host. By installing Postfix, creating a Mailgun account, and configuring the SMTP relay settings, you can enable email delivery through Mailgun on your Ubuntu server.

Official Documentation

How Pheonix Solutions Can Help

Reliable email delivery is essential for business communication, application notifications, and server alerts.

Pheonix Solutions provides DevOps, cloud infrastructure, server administration, and email configuration services to help businesses maintain reliable IT environments.

Our experts can help you configure SMTP relays, troubleshoot email delivery issues, manage mail servers, and improve server communication.

Contact our experts to discuss your email infrastructure requirements.

admin

Our team has expertise across software and web development, WordPress, e-commerce, mobile applications, UI/UX, cloud and infrastructure, DevOps, CI/CD, API integration, security, testing, automation, and technical support. The team also works with AI-based software solutions, LLMs, AI workflows, AI agents, and intelligent application development to help businesses automate processes and build smarter digital solutions. We focus on developing, deploying, maintaining, and optimising secure, scalable, and reliable technology solutions while helping businesses adopt modern technologies and drive digital transformation.

Leave a Comment

Scroll to Top