Implement a Reliable Email Delivery System for Your Website Using Mailgun

If you’ve ever had customers tell you that your website’s transactional email is constantly ending up in their SPAM/Junk folders or not received at all, this guide is definitely for you.

Transactional Email Types

  • Receipts and Confirmations (ex. Order confirmations).
  • Explicit Requests (ex. Password resets).
  • Account Alerts (ex. Failed payment attempts).
  • and more.

This guide will teach you how to easily implement this solution to send your customers emails with confidence.

Mailgun Pricing

Free Plan

Mailgun signup is simple and they have a FREE plan/trial that includes 5,000 emails for the first 3 months, which is good for testing or for those just starting out with a website.

  • 5,000 messages/month are included.
  • There is a limit of 300 messages per day on the included sandbox domain.
  • Data retention for Logs and the Events API is 1 day
  • You cannot create custom domains.
  • You can only send to Authorized Recipients, and there is a maximum of 5 Authorized Recipients.

Flex Plan

If you opt to enter your credit card, after the trial period (the first 3 months) has ended and if you haven’t opted to upgrade to one of their subscription plans, you’ll continue on Flex (i.e. pay-as-you-go) plan, in which you’d pay for any messages you send at a rate of $0.80/1,000 messages.

Flex Plan Highlights:

  • No daily sending limit.
  • 5,000 FREE messages a month for the first 3 months.
  • 5-day data retention for logs and the Events API.
  • Custom domains.
  • Use of Authorized Recipients is not required to send with custom domains.

Activate Your Account

For this guide, I jumped right to the Flex plan, so I could configure a custom domain, and because the pricing is so inexpensive, even if there were overages.

  1. Sign up for Mailgun.
  2. Enter payment information, unchecking the ‘Add payment info now’ box, unless you are comfortable with automatically being billed after the 3-month trial has ended.
  3. Click the ‘Create Account’ button and verify your account, using the email that Mailgun sends out.

Add and Verify Your Domain

After activating your account, Mailgun will drop you into your dashboard, where you will continue on with the instructions below.

  1. From your Mailgun dashboard, add your custom domain.
  2. Enter your domain name.
  3. Choose your Domain region to send mail from.
  4. Choose the strongest key length that your email system supports. (Note: Stick with the default option of 1024 if you don’t want to take the time to at least investigate implementing the stronger 2048 key length.).
  5. Click the ‘Add Domain’ button.

DNS Setup

  1. Go to the DNS provider you use to manage the domain you’re adding to Mailgun. (Note: Mailgun provides some links to some common DNS providers, so you might be able to save a bit of time.).

Pro Tip: Cloudflare is my recommended provider for the fastest DNS services and I’ve written the Implement Cloudflare’s CDN For Better WordPress Security And Performance.

  1. Add the DNS sending records that are provided by Mailgun. (Note: Most website owners will be able to skip the MX records, as those should already be added for use with solutions like Microsoft 365, Google Workspace, etc.).
  2. Click the ‘Verify DNS Settings’ button, once all the desired DNS records have been added. (Note: It can take up to 48 hours for the DNS settings to propagate across the web and that is why I highly recommend Cloudflare, which propagates almost instantly.).
  3. Continue clicking on the ‘Verify DNS Settings’ button, until Mailgun kicks you into their ‘Overview’ page, which means your DNS has been properly validated. (Note: You will also receive an email notification once DNS is ready to go.).

SPF Records

If you already have SPF records configured within your SMTP email service (Microsoft 365, Google Workplace, etc.) prior to setting up Mailgun for your domain, you’ll get a message saying that you can only have a single SPF record per domain.

Not to worry, as all you need to do is combine your SPF records into a single record.

For example, with Microsoft 365, you’ll have an SPF record of v=spf1 -all and for Mailgun, you’ll have an SPF record of v=spf1 ~all, so you will combine them to be as shown below.

v=spf1 -all

Sending API Keys

If you are setting up Mailgun for a handful of websites, using your account’s Private API key (the one created by default) is just fine. If the API key gets compromised, it would just be a matter of generating a new key and updating the key on your websites.

However, if you are managing say 10 or more websites or websites for clients, it would be a good idea to generate a Sending API Key for each website.

  1. Mailgun Dashboard > Sending > Domain Settings.
  2. Select a domain.
  3. Click on the ‘Sending API keys’ tab.
  4. Click on the ‘Add sending key’ button.
  5. Enter a sending key. (Note: Just keep the key super short and simple, as Mailgun will automatically generate a highly-secure/complex API key for you.).
  6. Click the ‘Create sending key’ button.
  7. Click the copy icon next to your new API Key and paste it into your website, which is covered in the following section.
  8. Rinse, repeat, for additional domains.

Configure Mailgun for WordPress

  1. Install and activate the official Mailgun plugin.
  2. Pull up the settings area of the plugin.
  3. Select Your Region > Ensure this setting matches what you chose in your Mailgun dashboard.
  4. Mailgun Domain Name > Ensure this setting matches what you chose in your Mailgun dashboard.
  5. API Key > Grab your Private API Key from your Mailgun dashboard (User Avatar > API Keys) and paste it here.
  6. From Address > Add an email address that matches your custom domain name (e.g.
  7. From Name > Add a name that matches your brand or business name (e.g. WP Turned UP).
  8. Override “From” Details > Set to ‘Yes’.
  9. Click the ‘Save Changes’ button.
  10. Click the ‘Test Configuration’ button.

If everything is configured correctly, you should receive a ‘Mailgun HTTP API Test Success; status “Success”‘ message.

You will also receive an email that confirms sending is working, which region Mailgun is sending from and which method (e.g. HTTP API) is being used.

At this point, all transactional emails (order information, subscription information, password resets, etc.) are automatically sent through Mailgun.

Multiple Domains Under One Account

The following steps show how to include additional domains under a single Mailgun account.

  1. Repeat the steps from the ‘Add and Verify Your Domain’ section, above.
  2. Repeat the steps from the ‘Configure Mailgun for WordPress’ section, above.
  3. Rinse, repeat, for any additional domains you would like to add.

Remove a Website From Your Account

If you have an account where you are managing multiple domains, the following steps help you to remove a specific domain, while keeping your Mailgun account active.

  1. Mailgun Dashboard > Sending > Click on the domain.
  2. Expand the ‘Sending’ menu item.
  3. Click ‘Domain Settings’.
  4. Advanced > Deleted Domain > Click ‘Delete’.
  5. Remove all Mailgun DNS entries from wherever you manage your DNS.
  6. WordPress Dashboard > Remove the Mailgun plugin.

Wrap Up

Getting ahead of your transactional email delivery issues is super important for your company’s reputation and internal success.

Mailgun’s Flex pricing is extremely low-cost, for what you get, so I see no downsides to implementing this solution on your website.