Mailgun Setup and Configuration Guide

Author

Reads 11K

A young delivery man carrying a package near an open delivery truck in the city street.
Credit: pexels.com, A young delivery man carrying a package near an open delivery truck in the city street.

To get started with Mailgun, you'll need to create an account. This is a straightforward process that can be completed in just a few minutes.

Mailgun offers a free plan, which is perfect for small projects or testing purposes. This plan includes 300 messages per day, which is a great starting point for most users.

To create an account, simply visit the Mailgun website and click on the "Sign Up" button. You'll be asked to provide some basic information, such as your name and email address.

Once you've created your account, you'll need to configure your Mailgun settings. This includes setting up your domain and verifying your email address.

What is Mailgun?

Mailgun is an email service that's specifically built for developers to send, receive, and track emails. It offers powerful tools to manage large amounts of emails and improve engagement.

Mailgun is a popular, reliable email service provider that can scale to support large quantities of emails. It uses a secure API and has a free 3-month trial.

Credit: youtube.com, What Is Mailgun? - TheEmailToolbox.com

Mailgun's setup can require more time than some other mailers, but it's this extra effort that allows it to be such a reliable email delivery service. You can set up Mailgun to send transactional emails, marketing campaigns, and notifications with ease.

Mailgun offers competitive pricing, starting at $0.80 per 1,000 emails beyond the free trial. Here's a breakdown of the costs:

  • Free account: Up to 5,000 emails per month for 3 months, restricted to sending to only 5 authorized recipients.
  • Pricing: $0.80 per 1,000 emails after the free trial.

To get the most reliable email delivery, Mailgun recommends using a domain-specific email address, such as [email protected].

Getting Started

To get started with Mailgun, you'll first need to create an account on their website. Signing up is free, but accounts without a credit card are limited to sending emails to only 5 recipients.

You'll need to add a credit card to your account to remove these restrictions, so be sure to have one handy. For more information on Mailgun's signup page, you can check it out.

After completing the short signup form, you'll have a couple of additional verification steps to complete. This is what allows Mailgun to ensure high standards of email deliverability for all their users.

You'll receive an email to verify your Mailgun account, and you'll need to click the Verify your email address button.

Configuration and Setup

Credit: youtube.com, How To Use Mailgun To Send Emails 2025! (Full Tutorial)

To configure Mailgun as a mail relay with Postfix, you'll need to connect to your instance using SSH and become a superuser. Set a safe umask with `umask 077` and install the Postfix Mail Transport Agent with `apt update && apt -y install postfix libsasl2-modules` or `yum install postfix cyrus-sasl-plain cyrus-sasl-md5 -y`.

You'll need to modify the Postfix configuration options by adding the Mailgun SMTP service to the `main.cf` file with `relayhost = [smtp.mailgun.org]:2525`. This is because port 25 isn't allowed on Compute Engine, so you must use port 2525. To enforce SSL/TLS support and configure SMTP authentication, add the following lines: `smtp_tls_security_level = encrypt`, `smtp_sasl_auth_enable = yes`, `smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd`, and `smtp_sasl_security_options = noanonymous`.

To test your configuration, install the `mailx` or `mailutils` package and send a test message with `echo 'Test passed.' | mail -s 'Test-Email' [email protected]`.

For another approach, see: Smtp Server Mass Email

Domain Name

To enter the Domain Name, you'll need to use the subdomain you created in Mailgun. For example, if your subdomain is mg.example.com, that's what you should enter here.

Make sure the verification process is complete before proceeding. This may take a while, so you might need to come back to this later.

Using a subdomain is recommended for your Mailgun setup.

Postfix Mail Relay Configuration

Credit: youtube.com, How to configure postfix mail server

To configure Postfix as a mail relay, you'll need to connect to your instance using SSH and become a superuser. This can be done by running the command `sudo su -` in the terminal.

To install the Postfix Mail Transport Agent, you'll need to run the command `apt update && apt -y install postfix libsasl2-modules` or `yum install postfix cyrus-sasl-plain cyrus-sasl-md5 -y`, depending on your Linux distribution.

When prompted, select the Local Only configuration and accept the default choices for domain names. This will set up the basic configuration for Postfix.

To modify the Postfix configuration options, you'll need to open the main.cf file using a text editor such as vi. This file is located at /etc/postfix/main.cf.

To add the Mailgun SMTP service, you'll need to add the following line to the end of the main.cf file: `relayhost = [smtp.mailgun.org]:2525`. Note that you must use port 2525 because port 25 isn't allowed on Compute Engine.

A fresh viewpoint: Mass Email Smtp

Credit: youtube.com, Postfix Mail Server Configuration on RHEL8 - Anand K

Here's a summary of the steps to configure Postfix as a mail relay:

  • Connect to your instance using SSH and become a superuser.
  • Install the Postfix Mail Transport Agent.
  • Modify the Postfix configuration options.
  • Add the Mailgun SMTP service to the main.cf file.
  • Save and close the main.cf file.
  • Generate the SASL password map.
  • Reload your Postfix configuration.

By following these steps, you'll be able to configure Postfix as a mail relay and start sending emails through your instance.

Features and Benefits

Mailgun offers a variety of features and benefits that can help you take your email marketing to the next level. With seamless email integrations, you can ensure speed, high reliability, and compliance with your industry standards.

Mailgun provides tools to help you improve email engagement, avoid spam filters, and increase the return on investment. This means that your emails are more likely to be opened and acted upon.

Here are some of the key features that make Mailgun stand out:

  • Sending Emails: Seamless email integrations with your systems ensure speed, high reliability, and compliance with your industry standards.
  • Optimizing Emails: Mailgun provides tools to improve email engagement, avoid spam filters, and increase the return on investment.
  • Email Validation: You can keep your email lists clean and lean with high-speed email validation from Mailgun.
  • Automation of Email Marketing: Mailgun enables the effective automation of email at scale, optimizing campaigns for better performance.
  • Blocking Spam Signups: Mailgun ensures that email addresses are genuine, blocking out fake signups.
  • Improved Deliverability: Mailgun provides expert guidance toward better engagement and higher conversions.

Features & Benefits

Mailgun offers a range of features and benefits that make it a powerful tool for sending and tracking emails.

One of the key features of Mailgun is its ability to ensure seamless email integrations with your systems, guaranteeing speed, high reliability, and compliance with industry standards.

For more insights, see: Gmail Smart Features

Credit: youtube.com, Features and Benefits

Mailgun also provides tools to optimize your email marketing, including improving email engagement, avoiding spam filters, and increasing return on investment.

With Mailgun, you can keep your email lists clean and lean with high-speed email validation, reducing bounce rates and increasing deliverability.

Mailgun is equipped with workflows and analytics that enable the effective automation of email at scale, optimizing campaigns for better performance using data-driven decisions.

Here are some key features and benefits of Mailgun:

  • Sending Emails: Seamless email integrations with your systems ensure speed, high reliability, and compliance with your industry standards.
  • Email Validation: High-speed email validation reduces bounce rates and increases deliverability.
  • Automation of Email Marketing: Workflows and analytics enable the effective automation of email at scale.
  • Blocking Spam Signups: Mailgun ensures that email addresses are genuine, blocking out fake signups.
  • Email Tracking and Analytics: Comprehensive insights into email deliveries, opens, clicks, bounces, and other engagement metrics.
  • Inbox Placement Tools: Tools designed to boost the likelihood of your emails reaching the inbox instead of the spam folder.
  • Deliverability Optimization: Improve the connection with recipients and enhance the reach of your email campaigns perfectly.

These features and benefits make Mailgun a valuable tool for anyone looking to optimize their email marketing efforts and improve deliverability.

Using Templates

Using templates is a game-changer for managing your email layout and design. Templates allow you to create message templates on your Mailgun account and then populate the data variables at send-time.

You can add template variables as a JSON stringified X-Mailgun-Variables header. For example, if you have a template to send a password reset link, you can do the following.

Delivery worker checks packages in a van on a city street, ensuring orders are ready for shipping.
Credit: pexels.com, Delivery worker checks packages in a van on a city street, ensuring orders are ready for shipping.

Templates enable you to handle the data on the client, while keeping your layout and design managed on the server. This approach simplifies the process of sending personalized emails.

By using templates, you can create a reusable structure for your emails, making it easier to send messages to multiple recipients with varying data.

A fresh viewpoint: Collaboration Data Objects

Security and Compliance

Mailgun takes care of suppressing bounced, unsubscribed, or spam-complained emails, keeping your email list clean.

This means you don't have to manually remove these emails, saving you time and effort. You can focus on sending targeted and effective emails to your subscribers.

Mailgun also ensures your email practices align with industry regulations, helping you maintain compliance and avoid penalties.

Security and Compliance

Maintaining a clean email list is crucial for any business. Mailgun automatically handles bounced, unsubscribed, or spam-complained emails to keep your list in order.

Having a clean email list helps prevent spam complaints and maintain a good email reputation. This is especially important for businesses that rely heavily on email marketing.

Free stock photo of royalguard, security
Credit: pexels.com, Free stock photo of royalguard, security

Mailgun ensures your email practices align with industry regulations to maintain compliance and avoid penalties. This is a major advantage, especially for businesses that handle sensitive information.

Mailgun maintains compliance with HIPAA, SOC I & II, and GDPR regulations. This gives businesses peace of mind knowing they're following the rules.

Here are some key benefits of Mailgun's compliance features:

Return Path

The Return Path is an essential setting to ensure you're notified if any messages bounce due to issues with the recipient's email. This is especially useful for monitoring email deliverability and making adjustments as needed.

To enable the Return Path, check the optional Return Path checkbox and set the return-path to match the From Email. This will allow you to receive emails if any messages bounce.

API and Development

Mailgun's API is a powerful tool for developers, making it easy to integrate email functions with applications across various programming languages. This seamless integration is made possible by Mailgun's RESTful APIs.

Credit: youtube.com, Mailgun Email API - Built for Developers by Developers

Developers can use Mailgun's API to design email functionalities that fit specific business needs, creating a more personalized user experience. This level of customization is a game-changer for businesses looking to stand out from the crowd.

Here are some key benefits of using Mailgun's API:

  • Seamless Integration: Mailgun's RESTful APIs make it easy to integrate email functions with your applications.
  • Customization Options: Developers can design email functionalities to fit specific business needs.

Change TLS Version in WP Mail SMTP

As of March 28, 2021, Mailgun will no longer support TLS 1.0 or 1.1 connections, so it's essential to update your TLS version.

To check which version of TLS your site is running, you'll need to reach out to your hosting provider for more information.

Changing your TLS version within WP Mail SMTP is a straightforward process, but first, you need to verify which version you're currently using.

You can then update your TLS version to a supported one, such as TLS 1.2 or 1.3, to ensure uninterrupted email sending.

API for Developers

As a developer, you're likely no stranger to the importance of a well-designed API. Mailgun's API is a powerhouse, offering seamless integration with your applications across various programming languages. This means you can easily incorporate email functions into your code without breaking a sweat.

Credit: youtube.com, APIs for Beginners - How to use an API (Full Course / Tutorial)

One of the standout features of Mailgun's API is its customization options. Developers can design email functionalities to fit specific business needs, creating a more personalized user experience for your users. This level of control is a game-changer for businesses looking to tailor their email communications.

Here are some key benefits of using Mailgun's API:

With Mailgun's API, you can say goodbye to custom coding and hello to efficient email management. Their API is designed to make your life easier, not harder.

Api Key

Your Mailgun API key is essential for integrating email functions with your applications. You can find it in the upper right corner of your Mailgun account by clicking on the small circle with your initials, then selecting the API Security option.

This will take you to a page that includes your Mailgun API keys, which you can use to configure WP Mail SMTP. You'll likely see 3 API keys: Verification Public key, HTTP Webhook Signing key, and Mailgun API keys. Be sure to use your Mailgun API key to avoid email deliverability issues on your website.

If this caught your attention, see: Email Addresses to Use

Credit: youtube.com, What Is an API Key? | How API Keys Work and Best Practices for Developers

To generate your Mailgun API key, scroll to the Mailgun API keys section and click the Create API key button. You can add a description for your API key to help you remember what you're using it for.

Here are the steps to generate a new Mailgun API key:

  • Scroll to the Mailgun API keys section and click the Create API key button.
  • Add a description for your API key.
  • Click the Create Key button.
  • COPY the new API key and store it somewhere safe and accessible.

Note that if you lose your Mailgun API key, you'll need to generate a new one by repeating these steps.

Pricing and Plans

Mailgun offers two pricing plans: Mailgun Send Pricing and Mailgun Optimize Pricing. You can choose the one that best suits your needs.

Mailgun's send pricing plans include a free plan that costs $0/month, allowing you to send 100 emails/day. The free plan also comes with ticket support, RESTful email APIs, 1 custom sending domain, tracking, and analytics.

The Basic plan starts at $15/month, with no daily limits, and includes 10,000 emails/month. You also get 1 custom sending domain and 1 API key.

Credit: youtube.com, How Much Does Mailgun API Cost? - TheEmailToolbox.com

The Foundation plan costs $35/month (after a 1-month free trial), and allows you to send 50,000 emails/month. It also includes an email template builder, 1,000 custom sending domains, and 5 days log retention.

The Scale plan costs $90/month (after a 1-month free trial), and allows you to send 100,000 emails/month. It also includes SAML SSO, dedicated IP pools, send time optimization, and live phone & chat support.

Mailgun's Optimize pricing plans start with the Starter plan, which is free for 1 month and then costs $49/month. It includes 2,500 email address validations, 25 inbox placement tests, and 500 email previews.

The Pilot plan is also free for 1 month and then costs $99/month. It includes 5,000 email address validations, 50 inbox placement tests, and 1,000 email previews.

The Contract plan is available for custom pricing and includes unlimited users, custom email address validations, custom inbox placement tests, and custom email previews.

Here's a summary of Mailgun's send pricing plans:

Mailer and SMTP

Credit: youtube.com, Setting Up Your SMTP Using Mailgun

Mailgun's SMTP relay allows seamless email sending directly through existing applications, without requiring custom coding.

Mailgun's SMTP relay offers authentication support, ensuring secure email sending with SMTP authentication protocols, including TLS encryption for added security.

You can configure Mailgun as a mail relay with Postfix, a mail transfer agent, to forward emails destined for remote delivery.

To do this, you'll need to connect to your instance using SSH, become a superuser, and set a safe umask, then install Postfix and configure its options.

Here are the Postfix configuration options you'll need to set:

  • relayhost = [smtp.mailgun.org]:2525
  • smtp_tls_security_level = encrypt
  • smtp_sasl_auth_enable = yes
  • smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
  • smtp_sasl_security_options = noanonymous

By following these steps, you can set up Mailgun as a mail relay with Postfix and start sending emails securely and efficiently.

Backup Connection

Setting up a Backup Connection is optional, but recommended to improve email deliverability. It serves as a backup in case your Primary Connection fails.

A Backup Connection isn't required to complete your Mailgun mailer setup, but it's a good idea to have one. This way, you can ensure that your emails get delivered even if your Primary Connection is down.

Credit: youtube.com, How to Fix WordPress Not Sending Email Issue | SMTP Server Setup Tutorial

To use a Backup Connection, you'll need to configure it separately from your Primary Connection. This allows you to send emails using different connections based on specific rules or conditions.

Want to send emails using different connections based on a set of rules or conditions? Be sure to check out our Smart Routing tutorial to learn more.

Take a look at this: Set up Html Mail Using Word

Mailer

To select the Mailgun option in the Mailer field, simply click on it. This will unlock a new Mailgun section where you'll need to enter your Mailgun API key and domain information.

You can find your Mailgun API key in your Mailgun account settings. To access these settings, log in to your Mailgun account and navigate to the API keys section.

Once you've entered your API key and domain information, you're all set to send authenticated emails with Mailgun.

Testing and Troubleshooting

To run Mailgun tests, you'll need to set a few environment variables. These include your domain name, which can be found in the Mailgun admin interface, and your Private API key, accessible from the Mailgun security page.

Credit: youtube.com, How to TEST MAILGUN (Step by Step) 2025

Setting MG_DOMAIN and MG_API_KEY will allow you to run various sending tests using the email address specified in MG_EMAIL_TO.

If you set MG_SPEND_MONEY, the part of the test that uses the API to send email will be run, but be aware that this will count against your quota and may cost you money.

To summarize, here are the environment variables you'll need to set for Mailgun testing:

  • MG_DOMAIN: Your domain name (from the Mailgun admin interface)
  • MG_API_KEY: Your Private API key (from the Mailgun security page)
  • MG_EMAIL_TO: The email address used in sending tests
  • MG_SPEND_MONEY: Optional variable to enable actual email sending and incur costs

Verify Status

Verifying your domain can take some time, and you'll need to check the status of your domain verification to see if it's complete. This can take up to 24-48 hours.

You can check the status of your domain verification by clicking the Verify DNS settings button in Mailgun. You'll need to keep this tab or window open, as we'll need it later.

The verification status will show an active status next to your domain name once Mailgun can verify the DNS changes you made. Just be patient and wait for the verification to complete.

Discover more: Dns and Mx Records

A Clipboard on the Dashboard
Credit: pexels.com, A Clipboard on the Dashboard

If you're using GoDaddy to manage your DNS, you'll need to remove your normal domain when entering the Hostname into your GoDaddy DNS. For example, instead of entering mg.yourdomain.com, you would only enter mg.

Mailgun will provide you with helpful links to find your site's DNS settings, so don't worry if you're not sure where to look. You can also check out WPBeginner's tutorial on DNS settings for more details.

Testing

To run the tests, you'll need to set some environment variables. MG_DOMAIN is the domain name registered in the Mailgun admin interface.

Setting these variables is crucial to get the tests up and running. You'll need to get the Private API key from the Mailgun security page and set it as the MG_API_KEY variable.

You'll also need to set MG_EMAIL_TO to the email address used in various sending tests. This ensures that the tests are sent to the correct email.

Bright yellow sticky note with holiday email marketing message clipped to a wireframe wall.
Credit: pexels.com, Bright yellow sticky note with holiday email marketing message clipped to a wireframe wall.

If you want to test the part of the test that uses the API to actually send email, you'll need to set MG_SPEND_MONEY. Be aware that this will count against your quota and cost you money.

Here are the required environment variables:

  • MG_DOMAIN: domain name registered in the Mailgun admin interface
  • MG_API_KEY: Private API key from the Mailgun security page
  • MG_EMAIL_TO: email address used in various sending tests
  • MG_SPEND_MONEY: optional variable to test API email sending (will cost money)

Pros and Cons

Mailgun offers a range of features that make it a popular choice for developers and businesses looking for an email delivery service.

Setting up Mailgun can be a challenge if you're not familiar with email systems, which may require some technical expertise.

One of the benefits of using Mailgun is that it provides a range of features that can be easily integrated into your system.

Getting help from customer support can take time, so it's essential to have a solid understanding of the platform before reaching out.

Mailgun's advanced tools can be a bit overwhelming for beginners, especially if you're not familiar with email systems.

Some advanced tools cost extra, which can add up and impact your budget.

Credit: youtube.com, mailgun Review: Great Developer Experience and Customer Features!

Occasionally, emails might still end up in spam or not get delivered, which can be frustrating for both you and your recipients.

Here's a summary of the pros and cons of using Mailgun:

  • Mailgun offers a range of features that make it a popular choice for developers and businesses.
  • Setting up Mailgun can be hard if you’re not familiar with email systems.
  • Getting help from customer support can take time.
  • It can be tough to learn how to use all the features, especially for beginners.
  • Occasionally, emails might still end up in spam or not get delivered.
  • Some advanced tools cost extra, which can add up.

Lamar Smitham

Writer

Lamar Smitham is a seasoned writer with a passion for crafting informative and engaging content. With a keen eye for detail and a knack for simplifying complex topics, Lamar has established himself as a trusted voice in the industry. Lamar's areas of expertise include Microsoft Licensing, where he has written in-depth articles that provide valuable insights for businesses and individuals alike.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.