Configure Subdomain for Mailgun in Digital Ocean

DNS
Email
DevOps
Archive
The DNS settings that Mailgun’s docs don’t quite get right for Digital Ocean.
Author

B. Talvinder

Published

June 17, 2015

From the Archive

Originally published in 2015 on talvinder.com. Some technical details may be outdated, but this remains here as part of the archive.

I really like Digital Ocean for its no-fuss, economical yet powerful servers.

Recently, I hit a snag trying to configure subdomain for mailgun using digital ocean’s DNS settings. No matter what I did, mailgun was failing to verify the domain. After sipping few cups of coffee and contemplating meaning of life, when microsoft is demo-ing holographic minecraft and I am struggling to configure a stupid mail domain, I woke from my slumber and finally got things to work.

Steps

Step 1. Add the subdomain, let’s say mail.example.com, as a new domain in Digital Ocean. Trying to add subdomain in the DNS settings of example.com itself, will mostly not work.

Step 2. Now in this new domain, add mailgun MX details as below. The settings shared in mailgun will not work, if used as is. You need to take care of few things:

Record Type Name Value Thing to take care of
A @ IP Address use @ not domain name
CNAME email mailgun.org. dot at the end of mailgun.org
MX 10 mxa.mailgun.org. dot at the end
MX 10 mxb.mailgun.org. dot at the end
TXT @ “v=spf1 include:mailgun.org ~all” wrap value in double quotes
TXT krs._domainkey “k=rsa; p=BIGCHARACTERSTRING” wrap in quotes; Name should be krs._domainkey NOT krs._domainkey.subdomain.domain.com
NS ns1.digitalocean.com. dot at the end
NS ns2.digitalocean.com. dot at the end

That’s it! You are done.

Why a subdomain?

If you are wondering why configure a subdomain – it’s good practice to configure subdomain for promotional or transactional emails because:

  1. Let’s say your domain is example.com and subdomain is mail.example.com
  2. You can send emails from google apps account via example.com but promotional/transactional emails should be via subdomain
  3. If subdomain gets blacklisted, your main domain stays clean

Enjoyed this?

Get frameworks, build logs, and field notes in your inbox.

No spam. Unsubscribe anytime.