Guides

Mailgun DNS records for SPF, DKIM, DMARC

19 November 2026

Mailgun asks for four kinds of DNS record on the domain you add: an SPF TXT record with include:mailgun.org, a DKIM TXT record with a key from your control panel, two MX records pointing at mxa.mailgun.org and mxb.mailgun.org, and a tracking CNAME pointing at mailgun.org. Those MX records send incoming mail for that domain to Mailgun. That is why most people add a subdomain such as mg.example.com to Mailgun, instead of the domain their staff receive mail on.

These notes follow Mailgun’s domain verification guide, checked in November 2026. Once the records are in, a $129 Snapshot reads SPF, DKIM, and DMARC for your sending domain from public DNS and lists anything still wrong.

The records

SPF

Mailgun lists SPF as required, with the value:

v=spf1 include:mailgun.org ~all

Publish it on the domain you added to Mailgun. If that name already has an SPF record, add include:mailgun.org to the existing record instead of creating a second one. Two SPF records on the same name cause a PermError, which fails SPF for all mail. See SPF PermError.

DKIM

Mailgun lists DKIM as a required TXT record. The value is in the Domain Verification & DNS section of the control panel for your domain. Copy both the host name and the value from there. The key is long, so if your DNS host limits TXT strings to 255 characters, see our guide to adding a DKIM record for how to split it.

Mailgun’s page notes that you may see more than one DKIM key listed, with some unverified. It says this happens after key rotation, or when manually created keys stay in the system after you turn on Automatic Sender Security. It says not every listed key has to verify: as long as the key the domain is configured to use is correct in DNS, Mailgun can sign.

MX

Mailgun lists two MX records as required:

10 mxa.mailgun.org
    10 mxb.mailgun.org

Mailgun says these receive and route messages sent to the domain. Read that carefully. If you add them to example.com and your team’s mailboxes are on Google Workspace or Microsoft 365, incoming mail for example.com starts going to Mailgun instead. That is the main reason to use a subdomain.

Tracking CNAME

Mailgun lists a CNAME pointing to mailgun.org as required for click, open, and unsubscribe tracking. It is not part of SPF, DKIM, or DMARC. On Cloudflare, set it to DNS only.

Use a subdomain

A subdomain such as mg.example.com or mail.example.com avoids the MX problem and keeps Mailgun’s records separate from your main domain’s. Microsoft’s SPF guidance recommends the same pattern for email services you do not control directly, such as bulk email services, so problems with that mail do not affect the reputation of your staff’s mail. Microsoft also notes each subdomain gets its own ten-lookup SPF budget.

The subdomain needs:

It does not need its own DMARC record. The parent’s DMARC record covers subdomains that do not have one. See DMARC for subdomains.

Root domain or subdomain: the trade-off

Putting Mailgun on the root domain works only if Mailgun is meant to receive that domain’s mail, or if no one receives mail there. For most businesses with staff mailboxes, that rules it out.

A subdomain has a small cost: you pick a From address on it, such as news@mg.example.com, or rely on relaxed alignment to send as example.com. In return, Mailgun’s records stay out of the way of your mailbox provider’s, its SPF include does not use up your root domain’s ten lookups, and a problem with bulk mail is less likely to touch the mail your team sends every day. Microsoft makes the same point about reputation in its SPF guidance.

DMARC and alignment

DMARC passes when SPF or DKIM passes on a domain that matches the From address. With Mailgun on mg.example.com:

If you have no DMARC record yet, publish one on the parent domain at p=none with an rua address, and read the reports before tightening it.

Verify

Mailgun says DNS changes can take 24 to 48 hours to propagate. It checks automatically, or you can click Verify DNS settings in the domain’s settings, or call the verify endpoint of its API.

To check yourself:

dig TXT mg.example.com +short
    dig MX mg.example.com +short

Use the DKIM host name from the control panel for the DKIM lookup. Then send a message through Mailgun to a Gmail address and use Show original. You want spf=pass, dkim=pass with your domain, and dmarc=pass. Our guide to reading email headers explains each line.

Common mistakes

Other senders

If you also send through SES or SendGrid, each has its own records and its own way to align. See our guides to Amazon SES and SendGrid. Keep a short list of every service that sends as your domain, and check it when anything changes.

Sources