Getting your email past spam filters and into your users inboxes is becoming increasingly difficult. Whether you own a website, an app or custom software – you need to reliably send emails without worrying about delivery.

Mailgun is a user-friendly and reliable email delivery service that I use for all my client’s websites, as well as my own.

Mailgun is a user-friendly and reliable email delivery service

It’s owner company Sinch is headquartered in Stockholm, Sweden, but bear in mind that the operations of Mailgun is located in San Antonio, Texas.

When setting up your mail delivery you are presented with the option to choose a region, either North America or Europe. Mailgun promises that message data is tied to your region of choice and never leaves the region that it is processed by.

Mailgun promises that message data is tied to your region of choice and never leaves the region that it is processed by

In this quick step-by-step tutorial I will go through how to setup Mailgun in two ways. First I’ll connect Mailgun to a WordPress website using an API key. Secondly I’ll show you how to connect to Mailgun using SMTP credentials.

You can get a long way with the free plan which sends up to 100 mails each day however if you need more domains, you will either have to purchase a subscription or setup a separate free account.

Mailgun plans

I’ll go through my most efficient setup which only takes about 10 minutes. Okay let’s get started.

Setting up your domain

Bear in mind that if you click “Start for free” you actually start a trial period with a paid plan. Instead click on Pricing and select “Try for free”. Next fill out your information and verify your email address.

To setup a Mailgun domain click "Send" then "Domains" and "Add new domain".

Next click “Send” then “Domains” and “Add new domain”.

Add new domain in Mailgun

Add you details:

  • Domain name: mg.yourdomain.com (It’s important to add “mg” before your domain name)
  • Domain region: Select your preferred region
  • DKIM length: Feel free to select either 1024 or 2048 (Bear in mind that some shared hosting providers does not allow for 2048 keys)

As you can see there are 5 DNS records, two “Sending records” two “Receiving records” and one tracking record. Go to your domain or hosting controlpanel and find your DNS settings.

Start by adding the two sending records, which are a TXT records.

Mailgun sending records

For the first sending record you need to choose:

  • Type: TXT
  • Name or Host: mta._domainkey.mg.yourdomain.com
  • Value: Shown above

Finish adding both sending records.

Next add the two receiving records. Be mindful that the MX records also has a “Priority” field which needs to be set to 10.

Mailgun receiving records

Now add the tracking record which is a CNAME record.

Mailgun tracking records

At the bottom of the “Domain settings” you have the option to enable DMARC as well.

Mailgun authentication records

I highly recommend enabling this, so go ahead and add that extra DNS record as well.

After you’ve added all DNS records go ahead and click “Verify”. Be mindful that DNS records can take some time to register, so you might have to wait and try again later.

Create a Mailgun API key

Go to your “Domain settings” and click “Sending keys” and “Add sending key”. Now copy and save the key since it will only be shown once.

Mailgun API key

Connect Mailgun to a WordPress website

To connect Mailgun to your WordPress website I recommend the plugin WP Mail SMTP which has the option to connect using your API key. Simply download the plugin and follow the instructions.

Mailgun setup with the WP Mail SMTP WordPress plugin
  • FROM email: Use an email address that matches your sending domain
  • Mailer: Choose Mailgun
  • Mailgun API key: Add the key
  • Domain name: Add the domain name mg.yourdomain.com
  • Region: The region you chose earlier

Lastly go to “Tools” and send a test email.

Create Mailgun SMTP credentials

Go to your “Domain settings” and click “SMTP credentials” and “Add new SMTP user”. Add a name and login name and click “Create”. Make sure to save your login and password.

Mailgun SMTP credentials

Connect Mailgun to MailPoet

To connect Mailgun to MailPoet using SMTP credentials start by installing the MailPoet WordPress plugin and going to “Settings” -> “Send with…” and choose “Other”.

Setup MailPoet with Mailgun SMTP credentials

Here you can add the SMTP credentials:

  • SMTP Hostname: smtp.eu.mailgun.org (Be mindful whether you are using EU or US servers)
  • SMTP Port: 25
  • Login: The login you just created
  • Password: Your password
  • Secure connection: No
  • Authentication: Yes

Now send a test email. If you get an error message and don’t receive a test email you have to begin testing different ports. Mailgun uses the ports 25, 587, 2525, and 465. Check for more information regarding ports here.

Summary

So I hope this gives you a realistic impression of how to setup Mailgun. This is it for this video, if you have any questions feel free to write in the comments below.  

Disclaimer: You can help support content creation. If you click some of my links, WP Explainer may get a compensation. I only partner with companies and products that I’d happily recommend to my audience.

Follow on Youtube

Follow to recieve the latest tutorials and courses

Related tutorials

How to create a child theme

Learn how to create a child theme from scratch for any theme.

How to install SSL on your WordPress site

How to install SSL on your WordPress site

In this quick tutorial you will learn how to get a green lock on your domains address bar by installing a Let's Encrypt certificate on your WordPress site.

How to install WordPress

How to install WordPress with Unoeuro 1-click installer

Step-by-step video tutorial on how to install WordPress with Unoeuro 1-click installer

How to install WordPress

How to install WordPress using FTP

Step-by-step video tuturial on how to install WordPress using FTP

Get the updates

Be the first to recieve the latest tutorials and courses.

"*" indicates required fields

This field is for validation purposes and should be left unchanged.