(Click on images to toggle small and large)

About Mailgun

Mailgun is a great service for companies that send marketing emails. You can configure very advanced scenarios and sorting all without managing an SMTP server on your own. You can turbocharge your mail sending and use many API functions and webhooks. It can be an awesome tool for a marketing company to manage email sequencing and analyze the results for open rates and many other metrics.

Mailgun is also great for solo developers and small site owners: you don't have to manage your mail server, you get free spam blocking and statistics, and until you start sending or receiving more than 10,000 emails a month it is free to use! You can also set up a catch all route instead of setting up different mailboxes for [email protected], [email protected], [email protected], [email protected], etc.

Today we are going to set up and test a new site. I already have a Mailgun account so we will be adding a new site.

Adding a New Domain To MailGun

  1. Log in to MailGun
  2. Click Settings->Domains
  3. Click Add New Domain

Use a Catch All Route

The advantage to a catch all is that you don't have to manage different email boxes for [email protected], [email protected], [email protected], [email protected], etc. They will all be forwarded to a single address of your choice either on or off your domain.

The disadvantage of this technique is that some mail programs will flag your account as a disposable e-mail address provider (DEA) and you will see a DomainIsWellKnownDea or ServerIsCatchAll error with certain mail validating services like https://verify-email.org/

So far I have not had trouble receiving email on accounts set up this way but rules and third party mail filters are constantly changing. If you expect to make a lot of money from an email address I would set up a real address.

Use a Subdomain

It is wise to follow the instructions and create a subdomain. This is most useful for managing mail campaigns.

However, to receive mail at [email protected] instead of [email protected] you also need to add a record without a subdomain.

On the next page, Mailgun prompts you with the keys you will need to set up your DNS records:

Set up DNS at your Digital Ocean account

Log in and click on your domain name to be taken to the DNS settings page:

Follow the prompts from MailGun to add a new record type in your DNS records.

Create the txt record at Digital Ocean:

If you make this mistake you will need to delete the DNS record and re-create it.

Create a second TXT record for your key. Correct subdomain this time:

Next create 2 MX records. MX stands for "Mail Exchange." In this example we are going to direct the traffic from mg.seniorwebdeveloper.life to mxa.mailgun.org and another backup record to mxb.mailgun.org.

Add the CNAME record for tracking:

When you are done your records should look something like this:

Go back to Mailgun and click Verify to confirm that everything works:

Fix any errors. There may be spelling issues or other gotchas.

Set up an email address and catch all address in MailGun

Go to Domain Settings and add a New SMTP User:

Use the credentials shown in your account to connect to Gmail (or any other service)

Set up your Gmail account to send and receive mail for this account

Go to your gmail account. Click on settings->accounts and Import -> Add another email address

We will set up for [email protected]:

Note the mg. username to match what Mailgun is expecting and also use the mailgun SMTP server (EDIT: THIS worked when I used mxb.mailgun.org as the SMTP server):

If this succeeds you will get an email from Gmail that looks like this :

Go back to your sign up page for Gmail and enter the code (or click on the link):

When you start receiving mail, you can view the details in the logs on MailGun. If you set up a forwarder to Gmail they will also show up there.

Testing the connections

Use https://www.mail-tester.com/ , https://verify-email.org/ or similar services to test your mail. You can also send from any other email account that you have access to. If you are using the same Gmail to manage this new account you can get some false positives because Gmail can route from one address to another internally and things can get generally weird.

You may see some errors:


  • 550 5.7.1 Relaying denied


  • Check the Routes in MailGun


  • DomainIsWellKnownDea or ServerIsCatchAll error


  • Don't use a catch all if this is important to you.

References (May contain Affiliate Links!):