How to Connect WordPress With Mailgun to Deliver Emails

Illustration by Sènga la Rouge illustration of hands connecting

If you’re struggling with the reliability and deliverability of your WordPress site’s transactional emails, connecting WordPress to Mailgun offers an easy way to improve the way that your WordPress site sends emails.

In its default state, WordPress uses PHP Mail to deliver your emails, which doesn’t work on all hosts and often ends with emails going straight to the receivers’ spam folders.

Mailgun offers a much more reliable way to send your WordPress site’s transactional emails, which is probably why you’re reading this tutorial right now. 

With the right plugin, you can even go beyond transactional emails and also use Mailgun to deliver marketing emails that you compose and send right from your WordPress dashboard.

In this post, we’ll share some of the best WordPress Mailgun plugins. Then, we’ll show you exactly how to set everything up, including what you need to do to authenticate your website with Mailgun.

Is Mailgun free?

Mailgun used to offer a forever free plan. However, in early 2020, Mailgun discontinued its forever free plan.

As of June 2020, you can get a three-month free trial that lets you send up to 5,000 emails per month. However, once those three months are up, you’ll need to pay to continue sending emails.

You can either use pay as you go pricing starting at $0.80 per 1,000 emails. Or, you can use pre-set plans that have some additional features, starting at $35 per month for up to 50,000 emails.

If you’re looking for a WordPress email sending service that’s 100% free forever, you might prefer other free SMTP server options such as:

Three best WordPress Mailgun plugins

A WordPress Mailgun plugin does two things:

  1. It helps you connect your WordPress site to Mailgun using Mailgun’s API or SMTP credentials.
  2. It replaces the default WordPress PHP mail method with Mailgun for all your transactional emails.

When you use one of these plugins, it will work for both the native WordPress emails and transactional emails from plugins such as form plugins or eCommerce plugins.

While there is an official WordPress Mailgun plugin, the official plugin doesn’t seem to receive much/any attention and the support forum is filled with unresolved issues. For that reason, we would recommend using a third-party plugin instead.

Here are three of the best options…

1. WP Mail SMTP


WP Mail SMTP is a popular plugin that comes in both a free version and a premium version with more features. It offers a simple setup process to help you connect using the Mailgun API.

To connect WordPress to Mailgun, all you need is the free version. However, if you’re willing to pay, you can also get access to in-dashboard email logging and a feature that lets you turn off specific WordPress emails.


  • You can connect via the Mailgun API.
  • It’s easy to use.


  • You need to pay for the email logging feature, which some other plugins offer for free. However, Mailgun offers its own email logging tool, so this isn’t that big of a deal.

2. MailPoet


MailPoet helps you connect WordPress to Mailgun so that you can deliver your site’s transactional emails with Mailgun.

However, unlike the other two plugins on this list, MailPoet also goes further and lets you send marketing emails using Mailgun. You can create one-time or automatic emails and set up everything from inside your WordPress dashboard with a drag-and-drop email editor.


  • It’s free for up to 1,000 subscribers.
  • MailPoet works for both transactional emails and marketing emails.
  • You can design emails from your dashboard using a drag-and-drop newsletter builder.
  • You can create automatic sequences based on WordPress content, like an automatic digest of your latest blog posts.
  • You can create email automation sequences, like sending abandoned cart emails on WooCommerce.


  • MailPoet uses Mailgun’s SMTP credentials rather than the Mailgun API. It still works fine, but some people prefer the API approach.

3. Post SMTP Mailer/Email Log


Post SMTP Mailer/Email Log is a relaunch of a popular plugin called Postman SMTP (which stopped receiving support – hence the relaunch).

It helps you connect WordPress to Mailgun using the API. It also supports lots of other services, including SendGrid and Gmail.

It will also log all of the emails that your WordPress site sends. And if you’re worried about deliverability issues, you can receive Chrome notifications or Slack messages if any emails fail to send.


  • It’s 100% free.
  • You can connect using the Mailgun API.
  • It helps you monitor your site’s emails for free, with features such as logging and failure notifications.


  • If you’re not going to use those advanced features, it has more features than needed to connect WordPress to Mailgun.

How to set up WordPress to send emails with MailPoet

For our WordPress Mailgun tutorial, we’ll use the free WP Mail SMTP plugin. However, if you’d prefer to use a different plugin, you should still be able to follow this tutorial because most of the steps are identical. The only thing that will change is the interface of the plugin that you’ve chosen.

Overall, you should be able to have your WordPress site sending emails through Mailgun with under 30 minutes of work.

If you’d prefer to watch this tutorial in video format, this eight-minute YouTube video covers most of the same steps from our tutorial. The video tutorial uses the official Mailgun plugin, but you can just follow the same steps using WP Mail SMTP instead:

1. Create a Mailgun account

To begin, you need to register for a Mailgun account. You will need to enter a credit card number to create an account with full features. However, Mailgun lets you send up to 5,000 emails per month for free for your first three months, and you won’t need to actually pay anything to follow this tutorial. 

However, if you continue using Mailgun once your three-month trial finishes, you will be billed (the default billing method is pay as you go pricing, starting at $0.80 per 1,000 emails).

Mailgun Signup

If you don’t want to enter your credit card information right now, you can uncheck the Add payment info now button. 

However, if you don’t enter a credit card for verification, Mailgun will only let your account send to five authorized recipients and otherwise limit your account’s features. This is useful to test – but you’ll need to add a credit card when you want to start using it on your live site.

2. Add and verify your domain name

If you want to send emails directly from your domain name, you need to verify your domain name with Mailgun.

You can technically skip this step, but it looks more professional to have a verified domain name and Mailgun will limit your account if you don’t.

This is the most technical part of the process – so once you make it through this, you’re basically home free!

To verify your domain name, you will need access to your domain’s DNS records. 

Typically, you’ll manage DNS records via your host. Unfortunately, the exact interface depends on your host, so we can’t cover every single scenario in this tutorial. If you’re not sure how to edit your domain’s DNS records, we recommend consulting your host’s knowledge base or reaching out to their support for help.

To get started, click this link or go to Sending → Domains → Add New Domain to add your domain name in Mailgun:

  • Enter your WordPress site’s domain name in the Domain name box. You can use your regular domain name unless you’re already using it for corporate email (e.g. Google G Suite). If you are already using G Suite, you can create a subdomain to use for Mailgun, e.g.
  • Choose your region.
Add WordPress domain to Mailgun

Once you click Add Domain, Mailgun will display four different DNS records that you need to add to your domain name:

  • Two TXT records
  • Two MX records
DNS records

To add these records, open your domain name’s DNS settings. Again, you usually manage these at your WordPress host – ask your host’s support for help if you can’t find them.

Here’s what the DNS management looks like at DigitalOcean – you can see how there are options at the top to add both MX and TXT records. At many hosts, you’ll make these selections using a drop-down instead:

Add DNS records

Add the TXT and MX records from your Mailgun account, making sure to pay attention to both the hostname and value:

  • When your hostname is identical to your domain name, you can just enter @.
  • For one TXT record, you can just enter the bolded part (mx._domainkey).

Here’s what it looks like to add a TXT record:

TXT record

Note how we only added mx._domainkey in the hostname box – we didn’t include the domain name.

Here’s what it looks like to add an MX record:

MX record

Note how we just included an @ symbol in the hostname box.

And here’s what it looks like after adding all four records:

All DNS records

Once you’ve added the records, go back to the Mailgun interface and click the Verify DNS Settings button:

Verify DNS settings

Note – it might take some time for the DNS records to update (up to 24 hours, but usually much faster). So if it doesn’t work right away, just wait 15 minutes and try again.

You should then see green checkmarks – that means success!


Now, you’re ready to start sending.

Optional: Enable Email Tracking

If you want to enable Mailgun’s tracking for clicks, opens, and unsubscribes, you’ll need to add one more DNS record – a CNAME record:

  • Hostname: email
  • Value:

This is not required to send emails – you only need this to enable tracking. If you don’t care about tracking, just skip this.

Here’s what it looks like to add the CNAME to your domain’s DNS records:

Tracking CNAME

3. Access Mailgun API key

Now, you’re ready to connect Mailgun to WordPress. To do that, you’ll use the API.

To access your Mailgun API key, go to Settings → API Keys. You want the Private API key value:

Mailgun API key for WordPress

Keep this value handy because you’ll need it in the next step.

4. Configure WP Mail SMTP

Now, go to your WordPress dashboard and install the free WP Mail SMTP plugin from

Once you’ve activated the plugin, go to the new WP Mail SMTP tab in your dashboard and select Mailgun as the Mailer. Then:

  • Add your API key.
  • Paste in the domain name that you verified in Step #2. This should be your main domain name, unless you created a subdomain for Mailgun.
  • Select your region (you also chose this in Step #2).
WordPress Mailgun API key added

You’ll also want to add your From email and From Name at the top of the plugin’s settings.

Once you save your settings, you should be all set!

5. Send a test email

To make sure your WordPress site is properly connected to Mailgun, the WP Mail SMTP plugin includes a feature to help you send a test email.

Go to the Email Test tab in the plugin’s settings and send a test email:

Send test email

6. Configure MailPoet (optional)

At this point, you can be done – your WordPress site will send all its transactional emails using Mailgun. That means all of your comment notifications, password resets, form notifications, etc.

But what if you want to go beyond transactional emails and also send marketing emails and newsletters via Mailgun?

To start sending marketing emails and newsletters via Mailgun, you can use the free MailPoet plugin to manage all of your email marketing efforts right from WordPress.

With MailPoet, you’ll be able to design one-off emails or automated sequences using a drag-and-drop editor and send all of your emails with Mailgun.

To set this up, you’ll need to use your Mailgun SMTP credentials, rather than the API:

Setting up Mailgun in MailPoet

You can find your SMTP credentials in your Mailgun dashboard. Go to Domains → [your domain] → SMTP:

Access Mailgun SMTP credentials for WordPress

7. View your email logs and analytics on Mailgun

Once you’ve sent some emails, Mailgun includes logging and analytics features to help you monitor and analyze your emails.

First off, you can go to Sending → Logs to see a list of all the emails that your site has sent:

Mailgun logs

If you enabled email tracking from Mailgun (by adding the CNAME record in Step #2), you can also view all of your email tracking analytics by going to Sending → Analytics.

Start using Mailgun on WordPress today

If you want to make sure your WordPress site’s emails make it to your users, you need to use a dedicated sending service such as Mailgun.

Mailgun no longer offers a forever free plan, but you can test it out for three months for free, with cheap pay-as-you-go pricing after that.

To connect Mailgun to WordPress, you’ll need to:

  • Choose a WordPress SMTP plugin that works with Mailgun.
  • Create a Mailgun account.
  • Authenticate your domain name with Mailgun by adding TXT and MX DNS records.
  • Add your Mailgun API key to your chosen plugin (or your Mailgun SMTP credentials).
  • Send a test email to verify that everything is working.

And if you want to also send WordPress newsletters and marketing emails with Mailgun, you can use MailPoet. Try it today – it’s free!