Configure subdomain for Mailgun in Digital Ocean


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 and sharing the details below for others:

Step 1. Add the subdomain, let’s say, as new domain in Digital Ocean. Trying to add subdomain in the DNS settings of 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 as given below.

Record Type Name Value Thing to take care of
A @ IP Address use @ not domain name
CNAME email dot at the end of
MX 10 dot at the end of
MX 10 dot at the end of
TXT @ “v=spf1 ~all” wrap the value in double quotes
TXT krs._domainkey “k=rsa; p=BIGCHARACTERSTRING” wrap the value in double quotes. And the Name should be krs._domainkey not
NS dot at the end
NS dot at the end

That’s it! You are done.

If you are wondering, why should we configure a subdomain – its a good practise to configure subdomain for promotional or transactional emails because of the following:

  1. Let’s say your domain is and subdomain is
  2. You can send emails from google apps account, mailgun, mandrill, whatever – using any email configured with For example, or
  3. But you cannot receive emails for a single domain. So if you have configured google apps or some other service to receive emails, you cannot configure another service, like mailgun, to receive emails.
  4. Hence, you need to setup a subdomain or some other domain to receive emails.
  5. Apart from the above reason, separation of concerns is good while configuring subdomains, for example

– for transactional emails
– for promotional emails
This separates the reputation of subdomains and hence the reputation of promotional emails will not affect transactional emails delivery.

Hope this helps someone!


Please enter your comment!
Please enter your name here