Mailgun DNS records

Mailgun asks for two TXT records (SPF and DKIM) before a domain can send, plus two MX records and a tracking CNAME that are optional for sending. Most people set it up on a subdomain such as mg.example.com, which keeps Mailgun's records away from the ones your normal email uses.

mg.example.com                 TXT    v=spf1 include:mailgun.org ~all
xyz._domainkey.mg.example.com  TXT    k=rsa; p=MIGfMA0GCSq...
mg.example.com                 MX 10  mxa.mailgun.org
mg.example.com                 MX 10  mxb.mailgun.org
email.mg.example.com           CNAME  mailgun.org

The DKIM host name and key are different for every domain, and EU-region accounts get different MX and tracking values. Copy yours from Mailgun.

Step by step

  1. In Mailgun, add a sending domain. Use a subdomain you don't use for anything else, like mg.example.com.
  2. Open the domain's settings and find Domain Verification & DNS. It lists every record with its host name and value.
  3. Add the SPF and DKIM TXT records at your DNS provider. These two are required: Mailgun won't send until DKIM checks out.
  4. 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.
  5. 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

Check it with a real message

Send one email through Mailgun to the address below and I'll show SPF, DKIM and DMARC as a receiving server sees them, along with the sending IP and its blacklists.

Related