How to Configure WordPress to Send Email Using Mailgun
By Colin Newcomer Published June 21, 2024Looking for the easiest way to set up WordPress Mailgun email sending on your site?
With a WordPress SMTP plugin like Gravity SMTP, you can easily configure your site to send all of its emails using Mailgun, including core WordPress emails as well as emails from plugins that you might be using (including Gravity Forms).
The default way that WordPress sends its emails often causes deliverability issues, either because the emails don’t send or the emails get flagged as spam.
By setting up Mailgun with Gravity SMTP, you can fix both types of problems by configuring your site to send all of its emails using Mailgun’s dedicated email sending service.
In this post, we’re going to show you exactly how to set up everything you need. We’ll start with quick introductions to Gravity SMTP and Mailgun and then we’ll get into a full step-by-step tutorial for setting up Mailgun email sending for WordPress.
Why Use Gravity SMTP for the WordPress Mailgun Integration?
Gravity SMTP is a WordPress SMTP plugin, which means its sole focus is on helping you connect your WordPress site to a dedicated email sending service like Mailgun.
Here are a few reasons why we think Gravity SMTP is the best WordPress Mailgun plugin:
- Support for core and plugin emails – in addition to letting you send core WordPress emails with Mailgun, Gravity SMTP also works for emails sent from plugins (as long as the plugins are using the regular WordPress email sending method, which most do).
- Easy setup – all you need to do is add your Mailgun API key to start sending emails.
- Testing tools – you can use multiple features to test the Mailgun connection and make sure everything is working.
- Detailed logging – you can keep track of all the emails that your site sends to detect issues.
- Support for multiple sending services – in addition to Mailgun, you can also connect other email sending services like SendGrid, Brevo, and more. You could configure one of these services to use as a fallback if you ever experience problems with Mailgun.
- Reliability and support – you can trust that Gravity SMTP is supported by the same team behind Gravity Forms and one of the most established companies in WordPress.
We also have a number of new features planned for Gravity SMTP, which are already on the Gravity SMTP roadmap.
If there’s a feature that you’d like to see, you can also vote on which features we should add to the roadmap, which will let you play a role in shaping Gravity SMTP to meet your needs for Mailgun WordPress email sending.
The Advantages of Using Mailgun Email Sending on WordPress
While there are a lot of quality email sending services out there, here are some of the main reasons to use Mailgun:
- Send 1,000 emails per month for free – while Mailgun doesn’t advertise it heavily, you can send up to 1,000 emails per month for free using the Flex plan.
- Pay-as-you-go pricing – in addition to its preset plans, Mailgun also offers flexible pay-as-you-go Flex pricing where you’re only billed based on your exact usage ($1 per 1,000 emails). Most other email sending services only offer preset plans.
- Good deliverability rates – Mailgun boasts 97%+ deliverability rates, which is well above the industry average of 85.7%.
- API setup method – once you’ve authenticated your domain name, it’s very easy to connect Mailgun to WordPress thanks to its dedicated API.
How to Set Up WordPress Mailgun Email Sending With Gravity SMTP
Now, let’s get into the step-by-step guide on how to set up WordPress Mailgun email sending using the Gravity SMTP plugin.
Here’s a high-level look at the process – keep reading for the full details:
- Install Gravity SMTP
- Create your Mailgun account
- Authenticate your domain name with Mailgun
- Access your Mailgun API key
- Configure Gravity SMTP to use Mailgun
- Test your site’s emails
1. Install the Gravity SMTP Plugin
To get started, you’ll want to install and activate the Gravity SMTP plugin on the site where you want to use Mailgun to send your emails.
Gravity SMTP is a standalone plugin. That is, you do not need to have Gravity Forms installed to use Gravity SMTP, though Gravity SMTP does work great for sending form notification emails.
Gravity SMTP is currently available to users with the Gravity Forms Elite license at no extra cost. If you have the Elite license, you can download the Gravity SMTP plugin from your Gravity Forms My Account area.
2. Register for Your Mailgun Account (If You Haven’t Done So Already)
If you already have a Mailgun account, you can skip ahead to the next step.
However, if you haven’t set up your Mailgun account yet, you’ll need to register for your account now.
Gravity SMTP will work with both Mailgun’s preset plans, as well as the pay-as-you-go Flex plans:
- Preset plans – there’s a free plan for testing that can work if you’re only sending emails to yourself. However, you’ll need one of the paid plans if you want to send emails to other users, as the free preset plan only lets you send to up to five authorized users. Paid plans start at the $35 per month for the Foundation plan.
- Flex plans – these let you pay based on your email usage at a rate of $1 per 1,000 emails, with no preset monthly charge. You can send up to 1,000 emails per month for free to any recipients (which lets you use it to email other users). However, you will still need to add your credit card even if you’re sending fewer than 1,000 emails per month.
In general, the Flex plans will be cheaper if you’re sending fewer than 35,000 emails per month, while the preset plans will be cheaper if you’re sending more than that.
There are also some feature differences between the Flex plans and preset pricing plans, though those differences probably won’t affect most WordPress sites.
3. Authenticate Your Site’s Domain Name With Mailgun
In order to properly send emails with Mailgun, you’ll need to authenticate your WordPress site’s domain name with Mailgun.
This is not a specific requirement of the Gravity SMTP plugin – it’s a basic requirement for sending emails with Mailgun and it will apply regardless of which WordPress SMTP plugin you use.
It basically does two things:
- It proves to Mailgun that you own/control your domain name, which helps them prevent abuse.
- It improves your deliverability by making your emails look more trustworthy to email clients’ spam filters.
Add a New Domain Name
Here’s how to get started:
- Go to Sending → Domains in your Mailgun dashboard. Or, click this link to open the correct dashboard board.
- Click the Add new domain button in the top-right corner.
On the next screen, you’ll need to make two choices.
First, you need to enter the domain name that you want to use for sending emails. You have two options here:
- Root domain name – you can use your root domain name – e.g. yoursite.com.
- Subdomain – you can use a subdomain – e.g. mg.yoursite.com.
Mailgun recommends using a subdomain instead of your root domain name, as it can avoid potential conflicts with other email tools that you’re using. Even if you use the subdomain approach, you’ll still be able to send emails from your root domain (e.g. [email protected]).
For this example, we’ll use a mg subdomain and we recommend using this approach for your site.
Next, you can choose your Domain region, which is the physical location of the server that will send your site’s emails. If you’re subject to EU regulations (e.g. your business is based on the EU), you’ll most likely want to choose the European option.
You can leave everything else as the defaults.
Once you’ve made your choices, click the Add Domain button.
Authenticate Your Domain Name
To authenticate your newly added domain name, you’ll need to add some DNS records to your domain name.
Mailgun will provide all of the records that you need to add on the page that it shows you after you add your domain name:
- Sending records – you’ll need to add SPF and DKIM values using TXT records.
- Receiving records – you’ll need to add MX records (which Mailgun still recommends even if you’re only sending emails).
- Tracking records – if you want to track opens, clicks, and unsubscribes, you’ll need to add a CNAME record.
To add these records, you’ll need to work from wherever you manage your domain’s DNS records.
Typically, you’ll manage your domain’s DNS records from your domain registrar, your hosting account, or a service like Cloudflare, depending on where you’ve pointed your domain’s nameservers.
Here’s what it looks like to add these records from Cloudflare, which is what we’re using for our test domain name.
After adding the DNS records, you should see green Verified icons appear next to each record in your Mailgun dashboard after clicking the Verify DNS Settings button.
Note: It might take a few hours for the changes to take effect, so don’t worry if you don’t see the Verified icons right away. Instead, just try again a little later.
If you need some help, you can check out Mailgun’s documentation article and Mailgun also has specific instructions for some popular domain registrars:
4. Access Mailgun API Key
After you’ve authenticated your domain name with Mailgun, you’ll need to create a Mailgun API key, which is what you’ll use to connect Gravity SMTP to Mailgun:
- Click this link to open the API security page. Or, you can click on your name in the top-right corner of the Mailgun dashboard and select API Security from the drop-down.
- Click the Add new key button in the Mailgun API keys section.
Give your API key a name in the popup that appears – this is just to help you remember what it does. Then, click the Create Key button.
Mailgun will then display your API key. Copy this API key to a safe spot because Mailgun will only show it once and you’ll need it in the next step.
Don’t worry, though. If you accidentally lose your API key, you can just repeat these steps to create another one.
5. Configure Gravity SMTP to Use Mailgun
Once you have your Mailgun API key, you’re ready to set up Gravity SMTP to start sending your WordPress site’s emails via Mailgun:
- Open your WordPress dashboard.
- Go to SMTP → Settings.
- Select the Integrations tab.
- Click the Gear icon next to Mailgun to open the Mailgun configuration settings.
Once you click the Gear icon, it should open a popup where you can configure Mailgun.
Here’s how to fill out everything:
- Mailgun API Key – paste in the API key that you got from the Mailgun dashboard in the previous step.
- Region – choose the same region that you selected when adding your domain to Mailgun in Step #3. For example, if you chose US when doing that, you should select US here.
- Default From Email – this will be the email address that your emails are sent from. For example, [email protected]
- Force From Email – if you enable this toggle, it will force emails from other plugins to also use this same “From Email” (regardless of how the plugin is configured).
- Default From Name – this will be the name that your emails appear as coming from.
- Force From Name – if you enable this toggle, it will force emails from other plugins to also use this name.
- Sending Domain – enter your domain name, which you should have already authenticated with Mailgun in the previous steps. If you authenticated a subdomain, you must enter that exact subdomain in this box. However, you will still be able to use your root domain name as the “From Email”.
Once you’ve added everything, make sure to click Save Changes.
To finish configuring WordPress to use Mailgun, you’ll want to make sure that the toggle is enabled for Mailgun in the Gravity SMTP integrations area.
You should see Connected once you enable the toggle.
6. Test Your WordPress Mailgun Setup
At this point, Mailgun email sending should be activated on your site.
To make sure everything is working properly, Gravity SMTP includes a test email feature:
- Go to SMTP → Tools in your WordPress dashboard.
- Select the Send a Test tab (it should open by default).
- Enter the email address to which you want to send an email in the Send To box.
- Click the Send Test button.
If it worked, you should see an Email successfully sent message.
And if you open your email inbox, you should see a test email that looks something like below.
In addition to making sure you receive the email, you’ll also want to check the “From Name” and “From Email Address” to make sure they appear as you want them to.
How to Monitor Your Mailgun WordPress Email Sending
Another nice thing about using the Gravity SMTP plugin is that it also gives you tools to monitor your site’s emails and detect any issues before they become bigger problems.
You can access your site’s email logs by going to SMTP → Email Log.
Here, you’ll see a list of all the emails that your site has sent, along with their status and basic details:
You can also use the options in the Actions column to see more details:
- View email log – see more technical details about that email, including which service it was sent with (e.g. Mailgun), the source of the email (e.g. a certain plugin), and more.
- View email – view a visual preview of the actual email.
By default, Gravity SMTP will log all of the emails that your site sends and permanently store them. However, you can adjust the storage period or completely disable the logging feature by going to SMTP → Settings → Logging.
Set Up WordPress Mailgun Email Sending Today
That wraps up our guide on how to use Gravity SMTP to configure WordPress to send email using Mailgun.
Once you’ve followed this tutorial, your site will have much more reliable email delivery. And with Gravity SMTP’s logging and testing tools, you’ll also be able to make sure everything stays working as you intend it to.
If you have a Gravity Forms Elite license and you’re ready to get started, install Gravity SMTP and you’ll be up and running with SendGrid email sending in no time.
If you want to keep up-to-date with what’s happening on the blog sign up for the Gravity Forms newsletter!