Step by step
- In Mailgun, add a sending domain. Use a subdomain you don't use for anything else, like
mg.example.com. - Open the domain's settings and find Domain Verification & DNS. It lists every record with its host name and value.
- Add the SPF and DKIM TXT records at your DNS provider. These two are required: Mailgun won't send until DKIM checks out.
- Add the two MX records if you want Mailgun to receive replies or bounces on that subdomain, and the CNAME if you want open and click tracking.
- Back in Mailgun, click Check DNS Records Now. DNS changes can take a while to show up; if a record isn't found yet, wait before changing it.
Do I add include:mailgun.org to my main SPF record?
Only if you send from the root domain itself. With a subdomain, Mailgun sends with a return address on mg.example.com, and receivers check SPF there, so the SPF record goes on the subdomain and your main record stays as it is. If you do send from the root, don't add a second SPF record: a domain can have only one. Put include:mailgun.org into the existing one, after v=spf1 and before the ~all or -all, and keep an eye on the limit of ten lookups.
Does the subdomain need its own DMARC record?
No. A subdomain falls back to the DMARC record on your main domain (_dmarc.example.com). Mail sent through Mailgun from [email protected] or [email protected] passes DMARC because Mailgun's DKIM signature is on mg.example.com, which counts as the same organisation. If you don't have a DMARC record yet, see setting up DMARC; Gmail and Yahoo require one from bulk senders.
The mistakes I see most
- The domain added twice. Most DNS hosts add your domain to the host name automatically. Typing
mg.example.comas the host givesmg.example.com.example.com. Enter onlymg, and onlyxyz._domainkey.mgfor DKIM. - Mailgun's MX records on the domain you receive mail on. If you point your main domain's MX at Mailgun, your normal inbox stops getting mail. This is the main reason to use a subdomain.
- Another record on the tracking host name. A CNAME must be the only record on its name. If
email.mgalready has something, pick a different tracking host name in Mailgun. - Records proxied through Cloudflare. DNS records for email must be "DNS only" (grey cloud).