The DNS records
Use the exact selector and value shown on your domain's DNS records tab: Mailgun says the selector is unique per sending domain.
Manual key for the sending domain mg.example.com
Type: TXT · Host: pic._domainkey.mg
k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQ…
Mailgun's examples also use krs, smtp and mailo as selectors. A 2048-bit key may need splitting into 255-character strings.
Automatic Sender Security, selector 1
Type: CNAME · Host: pdk1._domainkey.mg
pdk1._domainkey.9d876.dkim1.mailgun.com
9d876 is Mailgun's example; your account has its own value.
Automatic Sender Security, selector 2
Type: CNAME · Host: pdk2._domainkey.mg
pdk2._domainkey.9d876.dkim1.mailgun.com
Set it up and turn on signing
- In Mailgun, go to Send > Sending > Domains and click Add new domain. Mailgun recommends a subdomain such as
mg.example.comormail.example.com. - To have Mailgun manage keys, turn on Automatic Sender Security under Advanced settings. For an existing domain, use the Actions menu and Turn on automatic sender security in the Sending records section.
- For a manual key, open the domain's DNS records tab, click Create new DKIM, choose 1024 or 2048 bits, and click Create.
- Publish the records, click Check status, and activate a manual key from the gear icon with Activate.
- When moving to Automatic Sender Security, Mailgun keeps signing with the TXT key until the CNAMEs verify, then deactivates the manual keys.
DMARC alignment
Mailgun signs with the domain you added. A subdomain such as mg.example.com aligns under DMARC's relaxed mode with a From address at example.com, but not under strict mode (adkim=s), where the From domain must match exactly. An unverified domain shows as "sent via Mailgun.org" and is limited to 300 messages a day.
Key length and rotation
Manual keys are 1024 or 2048 bits, up to three per domain, and Mailgun recommends rotating at least every six months. Automatic Sender Security uses two 2048-bit selectors and rotates every 120 days by default; you can shorten or lengthen the period, with five days as the minimum. After a manual rotation, Mailgun suggests sending several test messages before deleting the old key. Not every listed key needs to show Verified, only the one that signs.
Common mistakes
- Guessing the selector. Mailgun assigns it per domain; copying
picfrom a guide when your domain useskrspublishes a key nobody looks up. - Publishing at the root. For
mg.example.comthe name is<selector>._domainkey.mgin theexample.comzone, not<selector>._domainkey. - Deleting the TXT key early. Keep it until the CNAMEs verify; Mailgun signs with it until then.
- Strict DKIM alignment with a subdomain.
adkim=sin your DMARC record fails mail signed formg.example.com.
Check your Mailgun DKIM key
Enter your domain and the selector from your Mailgun account. Free, reads public DNS only.
Frequently asked questions
What is Mailgun Automatic Sender Security?
A setup where you publish two CNAMEs, pdk1._domainkey and pdk2._domainkey, and Mailgun hosts 2048-bit keys behind them. It rotates them every 120 days by default, adjustable down to five days, with no DNS changes from you.
Why does Mailgun recommend a subdomain like mg.example.com?
Mailgun recommends a subdomain for deliverability: it keeps bulk or app mail separate from people's mail at the root. Its DKIM signature uses that subdomain, which still aligns with a From address at your root domain under relaxed DMARC.
How many DKIM keys can a Mailgun domain have?
Up to three manual keys per domain, which lets you publish a new one before retiring the old. With several active, Mailgun's docs describe choosing a signing key per message, so keep all published keys valid.
Sources
- Mailgun Documentation: DKIM security
- Mailgun Help Center: How can I rotate my DKIM key?
- Mailgun Help Center: Cloudflare DNS setup guide
- Mailgun Help Center: What domain name should I use with Mailgun?
- Mailgun Documentation: Domain verification
- RFC 6376: DomainKeys Identified Mail (DKIM) Signatures
- RFC 8301: Cryptographic Algorithm and Key Usage Update to DKIM
Checked against Mailgun's documentation on October 9, 2026. Providers change their setup screens; if yours differs, follow the values your admin console shows.
DKIM records for other providers
- Microsoft 365CNAME: selector1, selector2
- Google WorkspaceTXT: google
- Zoho MailTXT: you choose (e.g. zoho)
- GoDaddyCNAME: secureserver1, secureserver2
- FastmailCNAME: fm1, fm2, fm3
- Proton MailCNAME: protonmail, protonmail2, protonmail3
- Amazon SESCNAME or TXT: <token1>, <token2>, <token3> (Easy DKIM), your own (BYODKIM)
- SendGridCNAME or TXT: s1, s2
- PostmarkTXT: <timestamp>pm (e.g. 20131031155228pm)
- MailchimpCNAME: k2 and a second CNAME (Marketing), mte1, mte2 (Transactional)
- BrevoTXT or CNAME: mail (TXT), 2 CNAMEs from your account
- HubSpotCNAME: hs1-<number>, hs2-<number>
- KlaviyoCNAME: km1, km2 (marketing), kt1, kt2 (transactional), ks1, ks2 (service)
- SalesforceCNAME: you choose two (e.g. example-sf-a, example-sf-b)
- ZendeskCNAME: zendesk1, zendesk2
Compare every provider's selectors in one table · SPF record for Mailgun
Related guides
How to find a domain's DKIM selector, and check its key
Find a DKIM selector from the s= tag in an email header, see the selectors Microsoft 365, Google Workspace and common senders use, then check the key.
8 min read SPF, DKIM & DMARCHow to rotate DKIM keys without breaking email
How often to rotate DKIM keys, which key length to use, how to name selectors, and how to rotate in Microsoft 365, Google Workspace and on your own server.
9 min read SPF, DKIM & DMARCDKIM "body hash did not verify" and other DKIM failures: causes and fixes
Fix DKIM failures: body hash did not verify, signature did not verify, no key for signature and short keys. Causes from mailing lists to broken TXT records.
9 min readLast updated