Mikko's code blog

Mailgun DNS records on DigitalOcean

August 13, 2016 • ☕️ 2 min read

After adding your domain on Mailgun, you need to add DNS records on your DNS provider, in this case, DigitalOcean.

Mailgun recommends using a subdomain for sending mail with Mailgun. In my case the domain is mikkohaapanen.com and the subdomain I’ll add to Mailgun is mg.mikkohaapanen.com.

These instructions show the steps to add the subdomain records on DigitalOcean, but the steps are very similar if you choose not to use a subdomain for email.

Add New Domain on Mailgun

After adding the domain on Mailgun, you should see a page like this:

Mailgun DNS Records for the new domain

Adding DNS Records on DigitalOcean

DNS records on DigitalOcean can be managed in Networking menu.

Using a Subdomain For Email With Mailgun on DigitalOcean

If you use a subdomain, e.g. mg.mikkohaapanen.com, don’t modify DNS records for domain mikkohaapanen.com on DigitalOcean. Instead you need to add a new domain on DigitalOcean that is your Mailgun subdomain, e.g. mg.mikkohaapanen.com.

Separate domains for mg.mikkohaapanen.com and mikkohaapanen.com

If you choose not to use a separate subdomain, just add the records for the domain on DigitalOcean.

Add DNS Records For Sending

Two TXT records.

DNS Records on Mailgun

Add settings to DigitalOcean.

Adding first TXT record on DigitalOcean

Adding second TXT record on DigitalOcean

Note that the values must be added inside quotes.

Note that you don’t insert the whole domain, just the part in front of it. If you need to refer to the domain without any additional prefixes, use @.

Add DNS Records For Tracking

DNS Records on Mailgun

Adding CNAME record on DigitalOcean

Note that hostname must end in a dot.

Add DNS Records For Receiving

DNS Records on Mailgun

MX records on DigitalOcean

Note that hostname must end in a dot.


Now your DigitalOcean DNS records for the subdomain should look like this:

Finished DNS records on DigitalOcean

Next, go to Mailgun and check that the settings are working.

Check DNS records on Mailgun with Check DNS Records Now Button

Mikko Haapanen

Written by Mikko Haapanen who lives and works in Helsinki, Finland building useful things. Twitter