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.
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 | 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:
- Let’s say your domain is example.com and subdomain is mail.example.com
- You can send emails from google apps account via example.com but promotional/transactional emails should be via subdomain
- If subdomain gets blacklisted, your main domain stays clean