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.
| SPF | include:mailgun.org |
| DKIM | TXT (selector you choose) or CNAMEs pdk1/pdk2 |
| Bounce domain | Your Mailgun sending domain — SPF aligns |
| Set up in | Mailgun → 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.
| Name | Type | Value |
|---|---|---|
<selector>._domainkey | TXT | k=rsa; p=<key from Mailgun> |
pdk1._domainkey (Automatic Sender Security) | CNAME | pdk1._domainkey.<id>.dkim1.mailgun.com |
pdk2._domainkey (Automatic Sender Security) | CNAME | pdk2._domainkey.<id>.dkim1.mailgun.com |
email | CNAME | mailgun.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:
- Getting started Sending Email — documentation.mailgun.com
- Mailgun DKIM Security — documentation.mailgun.com