How to set up SPF, DKIM and DMARC for Mailgun

The SPF, DKIM, MX and tracking records Mailgun needs, set up on a subdomain.

Mailgun recommends sending from a subdomain like mg.yourdomain.com, and that one choice makes everything simpler: the records live on the subdomain, your main SPF record doesn't change, and DMARC still passes for your main domain. This guide follows that setup.

See what's already in place. Rigcheck shows your SPF, DKIM and DMARC records, and detects Mailgun once its records are published.

Before you start

  • A Mailgun account, and whether you're in the US or EU region. Some record values differ by region.
  • Access to your DNS host, wherever your domain's DNS records are managed (Cloudflare, GoDaddy, Namecheap, Route 53 and so on). This isn't always where you bought the domain. Rigcheck shows your DNS host at the top of your results.

Step 1: Add your sending domain

  1. In Mailgun, go to Send → Sending → Domains (or Domains in older layouts) and click Add new domain.
  2. Enter a subdomain such as mg.yourdomain.com.
  3. Turn on Automatic Sender Security if offered. Mailgun then rotates your DKIM keys for you.

Step 2: Add the DNS records

Mailgun lists the records under the domain's DNS records or verification page. For a subdomain called mg:

TypeNameValueWhat it does
TXTmgv=spf1 include:mailgun.org ~allSPF for the subdomain
CNAME or TXTFrom Mailgun (like pdk1._domainkey.mg)From MailgunDKIM: two CNAMEs with Automatic Sender Security, or one TXT key without it
MXmg10 mxa.mailgun.org and 10 mxb.mailgun.orgBounces and replies
CNAMEemail.mgmailgun.orgOpen and click tracking

EU accounts use mxa.eu.mailgun.org, mxb.eu.mailgun.org and eu.mailgun.org instead. Copy every value from Mailgun rather than from this table.

The SPF record goes on mg, not your root domain, so it's separate from your main SPF record. Don't add include:mailgun.org to your main record unless you send through Mailgun as your root domain itself.

Most DNS hosts add your domain automatically, so enter names in the short form your provider shows. Typing the full name can produce something like s1._domainkey.yourdomain.com.yourdomain.com, which silently fails. If you're not sure, add one record and look at how your host displays it.

If your DNS is on Cloudflare, set every CNAME record to DNS only (grey cloud), not proxied. A proxied record hides the CNAME, and verification fails.

Step 3: Verify

Back in Mailgun, click Verify DNS settings. Mailgun allows up to 48 hours, though it's usually much faster.

DMARC

If your domain has no DMARC record yet, add a TXT record named _dmarc:

Host_dmarc
TypeTXT
Valuev=DMARC1; p=none; rua=mailto:dmarc@yourdomain.com

If you already have one, keep it. A domain can only have one DMARC record, and it covers mail from Mailgun too. Start with p=none, then tighten it once your reports look clean: DMARC p=none vs quarantine vs reject walks through it.

The DMARC record goes on your main domain. Mail from mg.yourdomain.com passes DMARC for yourdomain.com under the default relaxed alignment.

Confirm it works

  1. Run your domain through Rigcheck. Check your sending subdomain: SPF should pass, and DKIM should show your Mailgun keys. Check your main domain for DMARC.
  2. Send a test message through Mailgun to a personal Gmail address. Open it, tap the three-dot menu and choose Show original. You should see PASS next to SPF, DKIM and DMARC, with your own domain listed for each.

Check your Mailgun setup. See which records pass and get the exact fix for anything missing.

Check my setup

Browse all guides