How to Set Up the Mailgun Mailer in WP Mail SMTP

Are you looking for a super reliable email delivery solution in WordPress that can work with your custom email address? Mailgun is a service specifically designed to help your emails get delivered successfully.

In this tutorial, we’ll walk you through how to fix email delivery issues in WordPress using Mailgun with WP Mail SMTP.


What is Mailgun?

Mailgun is a popular email service provider that can scale to support large quantities of emails. You can send 5,000 free emails per month for 3 months, though beyond that it’s a paid service.

While the setup for Mailgun can require more time than some other mailer options, these steps are what allow it to be such a reliable email delivery service.

Another important consideration when choosing a mailer is what you’d like your From Email to be. The From Email is the email address that emails appear to be sent from (the “sender”). Mailgun generally works fine with any From Email, however we recommend using a domain-specific email address (ie [email protected]) for most reliable email delivery.

Note: Would you like our team to do this setup for you? With White Glove Setup, we’ll do all configuration and testing for the Mailgun mailer on your site.

1. Signing Up for a Mailgun Account

To get started in this setup process, you’ll need to have a Mailgun account.

Creating a Mailgun Account

If you don’t already have an account with Mailgun, go ahead and sign up for an account on Mailgun’s website.

Sign up for a Mailgun account

Note: As an added verification step, Mailgun will require that you enter credit card information to set up an account (even if using a free account). For more information, please see Mailgun’s signup page.

After completing the short signup form, you’ll have a couple of additional verification steps to complete. Multiple levels of verification are what allow Mailgun to better ensure high standards of email deliverability for all of their users.

First, you should receive an email to verify your Mailgun account. You’ll need to click the link within this email in order to start the verification process.

Mailgun account activation email

After clicking the verification link in this email, you’ll be asked to enter a mobile number to receive a text verification code.

Send mobile verification code for Mailgun account

Once you’ve completed these steps, you should automatically be logged into your Mailgun account.

Adding a Domain

Now that you’re logged in, you should be seeing your Mailgun dashboard. When you’re ready, go to Sending » Domains in the left menu.

Open Domains page in Mailgun

On the Domains page, you’ll need to click the Add New Domain button.

Add new domain in Mailgun

Note: If you don’t see a button to add a new domain, this likely means that you haven’t yet entered a credit card. Mailgun requires all accounts (even free accounts) to enter a credit card before you can continue.

Next, you’ll need to enter a subdomain of your website’s domain name. A subdomain replaces the “www” part of your website’s address; for example: “subdomain.yourwebsite.com.” Subdomains can be used to add separate sections or directories to your website (similar to how some sites have blogs on a subdomain, such as blog.example.com).

In this case, the subdomain will be used by Mailgun only to send emails, and will not be visible on your site at all.

We’ll create the actual subdomain a little later. For now, you can just enter a subdomain such as mail.yourwebsite.com or mg.yourwebsite.com. It doesn’t really matter what you name it, but using “mail” or “mg” makes it more clear what the purpose of this subdomain is.

Enter a subdomain for Mailgun

Next, you’ll need to choose between two regions: US or EU. If your site is hosted in the European Union, then go ahead and choose EU. If your site is hosted anywhere outside of the European Union, then leave the default US option.

Choose a region for Mailgun to use

Last, we recommend keeping the Create DKIM Authority box checked for an extra mode of spam protection.

We also recommend selecting the 2048 option, which creates a longer DKIM key.

Create a DKIM Authority key

As we continue into the next step, be sure to keep this tab or window open as we’ll return to this page later.

2. Verifying Your Domain

As a way of both protecting site owners and their visitors, some SMTP services (including Mailgun) require that you verify your domain by adding records to your site’s DNS. You can find more information on the benefits of verifying your domain in Mailgun’s guide.

First, you’ll need to open your site’s DNS settings. If you’re not sure how to find these, Mailgun will provide you with some helpful links shown on their setup page when you’re adding a new domain.

DNS links for common hosting providers

Note: If you’re not sure where to find your site’s DNS settings or feel unsure about making changes, please contact your site’s hosting provider before making adjustments.

Or for more details on modifying a site’s DNS, you can check out WPBeginner’s tutorial on DNS settings.

Once your DNS settings are open, you should see an option to add a new record.

To make it possible for Mailgun to verify your domain, you’ll need to add two TXT records to your site’s DNS. Be sure to copy them carefully, as you’ll need the exact values from your Mailgun account for the verification to work.

DNS records needed for Mailgun

Note: If your DNS is managed by GoDaddy, then you will slightly adjust the Hostname shown in Mailgun. When entering the Hostname into your GoDaddy DNS, you’ll need to remove your normal domain. For example, instead of entering mg.yourdomain.com for the first TXT record’s Hostname, you would only enter mg

In your site’s DNS settings you may also see a TTL (Time To Live) field for the record. If you’re provided with a way to change this, we recommend setting the TTL to one day (or 86400 seconds, depending on the units your DNS uses).

Once you’ve added both TXT records, you’ll need to add MX records in exactly the same way. Just please remember that you must do this for the subdomain you created — not for the main domain.

Now that you’ve added both TXT and MX records, your DNS settings are all set.

Note: Mailgun will also show you a CNAME record, however you can ignore this as it’s not relevant when using Mailgun only to send emails.

3. Checking your Mailgun Verification Status

Now Mailgun will need to verify that your domain has proper DNS records. This verification can take a while (sometimes 24-48 hours) because DNS records may take some time to update.

You can check the status of your domain verification at any time by visiting the Domains page in your Mailgun account. Once Mailgun can verify the DNS changes you made, it will show an active status next to your domain name.

Check domain verification status

However, there’s no need to wait on this just yet! You can move ahead to the next step while you wait for this verification to complete. Just be sure to keep this tab or window open, as we’ll need it a little later.

4. Configuring WordPress to Send Emails

Now that you’ve set up your DNS, you can prepare your WordPress site to start using Mailgun with WP Mail SMTP for sending emails.

If you haven’t already, be sure to install and activate the WP Mail SMTP plugin.

After installing and activating this plugin, navigate to WP Mail SMTP » Settings to configure plugin settings.

From Email and From Name

At the top of this page, you can set the From Email and From Name. By default, these will fill with your site’s admin email and site name.

For the From Email, you can use any valid email address. However, for best results we recommend using a domain-specific email address (ie [email protected]).

You can also choose to check the box labeled Force From Email. If you’d like the From Email to be the same site-wide, this option will save you the trouble of editing the email settings throughout your site (in all form emails, etc).

Adjust From Email in WP Mail SMTP settings

You may add any From Name you’d like, and you can also choose to Force From Name to apply this setting site-wide.

Adjust From Name in WP Mail SMTP settings

Return Path

We also recommend checking the optional Return Path checkbox to Set the return-path to match the From Email. With this enabled, you’ll be emailed if any messages bounce as a result of issues with the recipient’s email.

Set return path to match From Email

Mailer

Next, in the Mailer field you’ll need to select the Mailgun option.

Select Mailgun mailer option

Now that you’ve selected Mailgun as your mailer, a new Mailgun section will appear. Here, you’ll need to enter API and domain information.

API Key

Even if your domain is still waiting to be verified, Mailgun will provide this information. You may even have automatically received an email containing your API key, otherwise you’ll need to return to the tab or window with your Mailgun domain details.

In the upper right corner of your Mailgun account, you’ll need to click on the small circle with your initials. Then, select the Security option.

Open Security page in Mailgun account

This will take you to a page that includes your API key. You’ll need to click the eye icon to view your full API key.

API keys page in Mailgun

Once you’ve copied the text for the full key, return to the WP Mail SMTP settings and paste it into the API Key field.

Note: If you have an older Mailgun account, you may see a prefix key- before your key. Be sure to copy this prefix and add it to your WP Mail SMTP settings as well, as leaving this out will cause issues with verification.

Domain Name

For the Domain Name, enter the subdomain you created in Mailgun (for example, mg.yourdomain.com).

Enter Mailgun settings in WP Mail SMTP

Region

Last, you’ll need to check the Region setting. This should match what you set up in Mailgun (anyone outside of the European Union should select the US option).

Mailgun Region

Once this information is complete, go ahead and save your settings.

5. Sending a Test Email

Note: Before proceeding with this step, make sure that the verification process from Step 3 is complete. This may take a while, so it’s possible you’ll need to come back to this later.

Once your domain is verified and your settings have been added to WP Mail SMTP, it’s important to send a test email to ensure that everything is working properly.

To do this, you’ll need to go to WP Mail SMTP » Settings and then click on the Email Test tab.

Open the Email Test tab in WP Mail SMTP

On this tab, you can enter any email address that you have access to and click the Send Email button.

After sending the email, you should see a success message.

Notice showing the WP Mail SMTP test email sent successfully

If you check the inbox for that email address, you should receive the email for this test.

Successful test email from WP Mail SMTP

It’s also a good idea to fill out a couple of test submissions for your forms after completing this setup to check that emails deliver successfully.

Frequently Asked Questions

Do I need to use a subdomain for my setup?

We do recommend using a subdomain for your Mailgun setup. By using a subdomain, this will help avoid potential negative impacts on your site’s deliverability in the future caused by conflicting DNS records.

Why are emails showing “On Behalf Of” in the sender information?

Certain email clients display this notation (also known as “On Behalf Of” notation) in specific circumstances. What this means is there is a mismatch between the domain being used in a site’s Sender field (e.g., mail.example.com) and the domain used within the site’s From field (e.g., example.com).

If you’d like to prevent your emails from sending in “behalf of” notation, then you’ll need to set your site’s From Email to use your Mailgun subdomain within your SMTP settings. It’s also a good idea to then carefully check your Reply To settings in all of your site’s forms, so that all of your users’ responses will be routed to an email that you have access to.

How do I change my TLS version within WP Mail SMTP?

TLS settings are controlled by a site’s hosting provider, so the easiest way to get this changed or updated would be to reach out to your host to have them make any adjustments.

Note: As of March 28, 2021 Mailgun will no longer be supporting TLS 1.0 or 1.1 connections. If you’d like to check which version of TLS your site is running, be sure to reach out to your hosting provider for more info.

That’s it! You have successfully set up your WordPress site to send authenticated emails with Mailgun.

Next, would you like to set up email logging to make sure you have a backup of all emails sent from your site? Be sure to check out our tutorial on using WP Mail SMTP to keep a log of all emails your site sends out.