How to set up SPF and DKIM for Mailgun

Short answer

For Mailgun, add and verify a sending domain (usually a subdomain like mg.yourdomain.com), then publish the SPF TXT (v=spf1 include:mailgun.org ~all) and the DKIM TXT record Mailgun generates. Using your own domain for DKIM is what aligns Mailgun mail with DMARC.

Verify the sending subdomain

Mailgun provides SPF, DKIM and tracking records for your sending domain. Publish them and verify in the Mailgun dashboard.

Keep DMARC aligned

Because DKIM is signed with your domain (or sending subdomain), DMARC passes on DKIM alignment. Confirm in your aggregate reports before enforcing.

  1. 1

    Verify the Mailgun DKIM record

    Check the selector:

    $ dig TXT smtp._domainkey.mg.yourdomain.com +short

Check your SPF record now

Open the free SPF checker →

Frequently asked questions

Should Mailgun use a subdomain?

Yes — a dedicated sending subdomain is Mailgun’s recommended setup and keeps your main domain’s reputation separate while staying DMARC-aligned.

Aligns with the Google/Yahoo 2024 sender requirements.

Reviewed by the Skysnag Security Team. Last updated .