Opens in a new tab

Mailgun SPF, DKIM and DMARC setup

Mailgun sends from a sending domain you add to it — Mailgun recommends a subdomain such as mg.yourdomain.com. That domain needs include:mailgun.org in its SPF record and a DKIM key: a TXT record by default, or two CNAMEs that Mailgun rotates for you with Automatic Sender Security.

SPFinclude:mailgun.org
DKIMTXT (selector you choose) or CNAMEs pdk1/pdk2
Bounce domainYour Mailgun sending domain — SPF aligns
Set up inMailgun → Domain Settings → DNS records

Is your domain set up for Mailgun?

We read your SPF record, look for Mailgun’s DKIM key and check DMARC. Nothing is stored.

SPF for Mailgun

Publish SPF on the sending domain you added to Mailgun — check that domain here, not your root domain, if you send from mg.yourdomain.com. If it already has an SPF record, merge Mailgun into it: v=spf1 include:<your server> include:mailgun.org ~all.

If you have no SPF record yet, publish this TXT record on @ (the domain itself):

v=spf1 include:mailgun.org ~all

If you already have one, add include:mailgun.org to it, before the ~all or -all at the end. A domain must have exactly one SPF record: a second one makes both fail.

include:mailgun.org uses 5 of the 10 DNS lookups an SPF record is allowed (measured 27 September 2026). Past 10, receivers fail SPF for all of your mail. What is inside include:mailgun.org, and whether you need it →

DKIM for Mailgun

In Mailgun, open the domain’s DNS records (Domain Settings → DNS records). By default DKIM is a TXT record under a selector you can choose, 1024 or 2048 bits. With Automatic Sender Security it is two CNAMEs, pdk1 and pdk2, with 2048-bit keys Mailgun rotates every 120 days by default.

Mailgun also lists a tracking CNAME (email → mailgun.org) and, to receive bounces and replies, MX records mxa.mailgun.org and mxb.mailgun.org at priority 10.

NameTypeValue
<selector>._domainkeyTXTk=rsa; p=<key from Mailgun>
pdk1._domainkey (Automatic Sender Security)CNAMEpdk1._domainkey.<id>.dkim1.mailgun.com
pdk2._domainkey (Automatic Sender Security)CNAMEpdk2._domainkey.<id>.dkim1.mailgun.com
emailCNAMEmailgun.org

The exact values come from Mailgun; copy them from there. Placeholders are in angle brackets.

Bounce domain and DMARC

Mailgun’s bounce address is on your sending domain, so SPF aligns when the From address uses the same domain (or its parent, under relaxed alignment). With DKIM on that domain too, Mailgun mail passes DMARC on both.

No DMARC record yet? Start with one that only reports, read the reports for a couple of weeks, then tighten it: build it with the DMARC generator.

Common mistakes

  • Checking the root domain when mail is sent from mg.yourdomain.com — the records belong on the sending domain.
  • Two SPF records on the same name.
  • A 2048-bit TXT key longer than some DNS hosts accept without splitting.

Questions

Should I send from my root domain or a subdomain?

Mailgun recommends a subdomain such as mg. or mail., which keeps its reputation and records separate from your team’s own mail.

Sources

Checked against Mailgun’s own documentation on 25 September 2026:

See every service’s mail pass or fail

Point your DMARC reports at us and we name every server sending as your domain, with what passes, what fails and the exact fix. Free for your first domain.

Create a free account