How to Set Up DKIM for Mailgun
Step-by-step guide to configure DKIM for Mailgun. Learn how to verify your domain, add DNS records, and ensure your transactional emails are authenticated.
Last updated: 2026-01-28
Mailgun is a powerful transactional email service used by developers and businesses. Proper DKIM configuration ensures your emails are authenticated and delivered reliably.
Why Set Up DKIM in Mailgun
Without DKIM:
- Emails may be flagged by spam filters
- Deliverability suffers, especially at scale
- Recipients' email servers can't verify authenticity
With DKIM:
- Emails are cryptographically signed
- Better inbox placement
- Improved sender reputation
- Compliance with email authentication requirements
Before You Start
You'll need:
- A Mailgun account
- Access to your domain's DNS settings
- The domain you want to send from
Mailgun's domain verification process sets up both DKIM and SPF records. You'll add multiple DNS records in one process.
Step-by-Step Setup
Access domain settings
Log into Mailgun. Go to Sending → Domains → Add New Domain (or select an existing domain).
Add your domain
Enter the domain you want to send from. Mailgun recommends using a subdomain (like mail.example.com) to separate your email reputation from your main domain.
View DNS records
Mailgun displays all the DNS records you need to add:
DKIM Records (TXT):
smtp._domainkey.yourdomain.comwith a DKIM public key value- Or a newer format with different selectors
SPF Record (TXT):
yourdomain.comwithv=spf1 include:mailgun.org ~all
MX Records (if receiving email through Mailgun)
Add DNS records
Log into your DNS provider and add the records:
For DKIM:
- Type: TXT
- Host:
smtp._domainkey(or as specified) - Value: The full DKIM value starting with
k=rsa; p=...
Verify in Mailgun
Return to Mailgun and click Verify DNS Settings.
Mailgun checks each record and shows green checkmarks when verified.
Verify Your Setup
After Mailgun verifies your domain, test the DKIM record publicly.
Common Mailgun selectors:
smtp._domainkey.yourdomain.commailo._domainkey.yourdomain.com
Check what Mailgun provided during setup—selectors may vary.
Mailgun DKIM Record Format
Mailgun typically uses a TXT record format:
k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQ...
Note that Mailgun's format doesn't always include v=DKIM1; at the beginning—this is valid, as the version tag is optional.
Common Issues and Solutions
"Unverified" status
Cause: DNS records not found or incorrect.
Solutions:
- Wait for DNS propagation (15-30 minutes typical)
- Double-check the record values match exactly what Mailgun provided
- Ensure you added TXT records, not CNAME records (for DKIM)
- Verify there are no extra spaces or truncation in the value
Record shows "hostname" in Mailgun
Cause: The DKIM record name may need adjustment.
Solution: Some DNS providers want just the subdomain (smtp._domainkey), others want the full name. Try the format your provider expects.
Emails sent but DKIM fails
Cause: Possible mismatch between sending domain and DKIM domain.
Solutions:
- Ensure you're sending from the verified domain
- Check that your code specifies the correct "From" domain
- Verify the domain in your Mailgun API calls matches the verified domain
Subdomain best practice
Mailgun recommends using a subdomain (like mg.example.com or mail.example.com) for sending. This isolates your email reputation and makes DNS management easier.
Mailgun + Common Integrations
WordPress + Mailgun
When using the Mailgun WordPress plugin:
- Set up DKIM in Mailgun first
- Configure the plugin with your Mailgun API key
- Set the "From" address to use your verified domain
Laravel + Mailgun
In your .env:
MAIL_MAILER=mailgun
MAILGUN_DOMAIN=mg.example.com
MAILGUN_SECRET=your-api-key
Ensure MAILGUN_DOMAIN matches your verified domain in Mailgun.
EU vs US Regions
Mailgun has different API endpoints for EU and US regions. Your DNS records are the same, but ensure:
- EU accounts: Use
api.eu.mailgun.net - US accounts: Use
api.mailgun.net
The region doesn't affect DKIM setup—just API calls.
Complete Your Email Authentication
Mailgun's verification process includes SPF recommendations, but verify everything:
SPF: Ensure your SPF record includes Mailgun:
include:mailgun.org
Check at spfrecordcheck.com.
DMARC: Set up a DMARC policy. Check at dmarcrecordchecker.com.
Related Articles
Monitor Your DKIM Records
Checking once is good. Monitoring continuously is better. The Email Deliverability Suite watches your SPF, DKIM, DMARC, and MX records daily and alerts you when something breaks.
Never miss a DKIM issue
Monitor your SPF, DKIM, DMARC and MX records daily. Get alerts when something breaks.
Start Monitoring