ReplyDak

How to set up SPF, DKIM and DMARC for Mailgun

Updated 10 November 2026 · 5 min read

Short answer

For Mailgun, add your sending domain (Mailgun recommends a subdomain such as mg.yourdomain.com), then publish the records from the Domain Verification & DNS section: SPF v=spf1 include:mailgun.org ~all on that domain, the DKIM TXT record exactly as shown, MX records mxa.mailgun.org and mxb.mailgun.org (priority 10) if you want Mailgun to receive mail, and the tracking CNAME. Add DMARC on the organisational domain at _dmarc.yourdomain.com.

Records for a Mailgun sending domain

TypeName (for mg.yourdomain.com)ValueRequired?
TXTmgv=spf1 include:mailgun.org ~allYes
TXTthe DKIM host shown (e.g. xyz._domainkey.mg)k=rsa; p=…Yes
MXmgmxa.mailgun.org and mxb.mailgun.org, priority 10Only to receive or route replies via Mailgun
CNAMEemail.mgmailgun.org (EU accounts use the EU host shown)For open/click tracking
TXT_dmarcv=DMARC1; p=none; rua=mailto:dmarc@yourdomain.comYes, on the root domain

Why Mailgun suggests a subdomain

Putting transactional or bulk mail on mg.yourdomain.com keeps it out of your root SPF record (so your staff mailboxes' SPF stays under 10 lookups), keeps its reputation separate, and leaves the root MX pointing at your normal mailbox provider. DMARC on the root still covers the subdomain unless you set a separate sp= or a record at _dmarc.mg. Under relaxed alignment, DKIM signed by mg.yourdomain.com aligns with a From address at yourdomain.com because they share the organisational domain.

Step by step

  1. 1

    Add the domain

    In Mailgun, Sending → Domains → Add new domain. Enter the subdomain and pick the region (US or EU). The EU region shows different hostnames: use what your panel shows.

  2. 2

    Copy records from Domain Verification & DNS

    Mailgun can show more than one DKIM key; publish the one that matches your domain's configuration, exactly as shown.

  3. 3

    Enter host names relative to your zone

    If your DNS host appends the domain, the SPF host for mg.yourdomain.com is just mg, and the DKIM host is the selector part plus ._domainkey.mg.

  4. 4

    Verify

    Click Verify DNS settings. Records published at a registrar that is not your DNS host never verify; check where your nameservers point.

Sending from the root domain instead

If you must send from yourdomain.com itself, add include:mailgun.org to your existing root SPF record rather than creating a second one, and do not replace your mailbox provider's MX records with Mailgun's unless Mailgun should receive all mail for the domain.

Check the result

Check mg.yourdomain.com (the subdomain) as well as the root domain. Run the domain through the free ReplyDak deliverability check: it reads MX, SPF, DKIM and DMARC live from public DNS, counts SPF lookups and checks the main blocklists, with no sign-up. If your DKIM selector is not a common one, type it into the optional selector box.

More setups and errors: SPF, DKIM and DMARC by provider, DNS host and error.

FAQ

What is Mailgun's SPF include?

include:mailgun.org, typically in v=spf1 include:mailgun.org ~all on the Mailgun sending (sub)domain.

Do I need Mailgun's MX records?

Only if Mailgun should receive mail for that domain or subdomain. For a dedicated mg. subdomain they are recommended; never swap your root MX by accident.

Does DMARC on my root domain cover mg.yourdomain.com?

Yes, subdomains inherit the parent DMARC policy unless they have their own record or you set sp=.

Sources

Related

Microsoft 365 mailboxes are coming soon. Until then, new orders use Google Workspace mailboxes.