Mailgun: verify your sending domain
What this guide is for
Mailgun sends your emails from its servers for a domain (or subdomain) that you register. Mailgun requires two TXT records, SPF and DKIM, to verify that you own the domain and to sign your messages.
Expected records
Mailgun often recommends a dedicated subdomain, for example mg.example.com. The records then go on that subdomain.
| Type | Name (host) | Value |
|---|---|---|
| TXT (SPF) | mg (or your sending domain) |
v=spf1 include:mailgun.org ~all |
| TXT (DKIM) | <selector>._domainkey.mg |
public key provided by Mailgun (k=rsa; p=...) |
| TXT (DMARC) | _dmarc (root domain) |
v=DMARC1; p=none; rua=mailto:[email protected] |
- The DKIM selector is assigned by Mailgun (for example
pic): only use the value shown for your domain. - If an SPF record already exists on that name, do not create a second one: add
include:mailgun.orgto the existing record. One SPF record per host name, 10 DNS lookups at most. - Mailgun offers 1024-bit or 2048-bit keys. Some hosts do not accept 2048 bits, or require splitting the value into 255-character strings.
- Mailgun may also show optional records (MX for receiving, CNAME for link tracking). Only add them if you use those features.
Steps in Mailgun
- In the Mailgun control panel, add your sending domain under Sending > Domains and choose the DKIM key size.
- Open Sending > Domain settings > DNS records to display the records to create.
- Create the TXT records at your DNS host.
- Return to DNS records and click Check status. Verification often takes 5 to 30 minutes, sometimes longer.
Check the setup
- Check the records:
dig -t TXT mg.example.com(SPF) anddig -t TXT pic._domainkey.mg.example.com(DKIM, with your selector). Test with a public resolver and with your local resolver. - In Mailgun, the domain should be verified.
- Send a test email to Gmail and check for
DKIM: PASSwith your domain. - Run a new scan in this tool.
DMARC
Publish a single TXT record at _dmarc.<your root domain>, starting with monitoring:
v=DMARC1; p=none; rua=mailto:[email protected]
A subdomain such as mg.example.com is covered by the root domain's DMARC record. Read the reports for a few weeks, then move gradually to p=quarantine and p=reject.