Configuring your domain with Mailgun SPF and DKIM records is essential for improving email deliverability, protecting your domain from spoofing, and ensuring your messages reach recipients’ inboxes instead of spam folders.
SPF (Sender Policy Framework) verifies that Mailgun is authorized to send emails on behalf of your domain, while DKIM (DomainKeys Identified Mail) adds a cryptographic signature to prove the message’s authenticity.
In this guide, you’ll learn how to locate your Mailgun SPF and DKIM records, add them to your domain’s DNS settings, and verify their correct setup for reliable and secure email sending through Mailgun.
How to Configure Your Domain with Mailgun SPF and DKIM Records
To configure your domain for sending emails through Mailgun, it has to be verified by setting up the SPF and DKIM records to your domain provider’s DNS management section.
The DKIM or Domain Keys Identified Mail is an encryption authentication method that is used to ensure that the email is originated from an authorized system and it prevents spammers from stealing the identity of legitimate entities.
Whereas SPF or Sender Policy Framework is used to improve email reliability and prevent spoofing.
The SPF and DKIM DNS records allow Mailgun to deliver email for the domain.
Steps to Configure Your Domain with Mailgun SPF and DKIM Records
Step #1 - Find the SPF and DKIM records on Mailgun Account:
Once you have added your domain to your Mailgun account, you’ll find the SPF and DKIM DNS records when you click on your added domain under the Domains tab in the Mailgun control panel.
The two TXT records for SPF and DKIM are listed under the Sending section.
Step #2 - Add the SPF TXT Record:
Go to your domain provider’s dashboard and open the DNS Management section. Create a new TXT record with the following values:
Record Type:
TXTName/Host:
@Value:
v=spf1 include:mailgun.org ~all(or the SPF value shown in your Mailgun control panel)TTL: Automatic, or the lowest value allowed
Save the record.
Note: A domain can have only one SPF record. If you already have one, add include:mailgun.org to it instead of creating a second record.
For example: v=spf1 include:existing-provider.com include:mailgun.org ~all.
For Value use: copy/paste the DKIM from the Mailgun control panel as shown in Step #1.
Step #3 - Add the DKIM TXT Record:
Create another TXT record with the following values:
Record Type:
TXTName/Host:
<prefix>._domainkey(use the exact host name shown in your Mailgun control panel as per Step #1)Value: Copy and paste the complete DKIM value from your Mailgun control panel. It begins with
v=DKIM1; k=rsa; p=followed by your unique public key.TTL: Automatic, or the lowest value allowed
Save the record.
Step #4 - Check the SPF and DKIM using Online Tool:
Once the SPF and DKIM TXT records for Mailgun are added at the domain registrar DNS, propagation will take some time.
To check whether SPF and DKIM records have been set correctly at the domain provider and propagated fully, any records checker such as the mail tester’s tool can be used.
DNS changes can take up to 24 hours to propagate globally. If verification fails right after adding the records, wait a few hours and check again.
Troubleshooting SPF and DKIM Issues
If Mailgun doesn’t verify your domain, or your emails are rejected or marked as spam, check the following:
DKIM record not verified: Make sure you used the exact DKIM value from your Mailgun account. DKIM records are unique to each provider and domain. If you have changed email providers, delete the old DKIM record before adding the new one, and never mix DKIM records from different providers.
Incorrect record format: The DKIM Name/Host must match the one shown in Mailgun exactly. The Value must begin with
v=DKIM1; k=rsa; p=and contain the full public key with no line breaks or extra spaces. The SPF record must be added to the root domain (@) and begin withv=spf1.Multiple SPF records: Having more than one SPF TXT record on the same domain invalidates SPF. Merge them into a single record.
Emails rejected as phishing: Even with correct SPF and DKIM, make sure the sender address matches the authenticated domain. If rejections continue, review your sending domain and email content against Mailgun’s anti-phishing policies, or contact Mailgun support.
DNS propagation delays: Changes can take up to 24 hours to take effect. Wait and recheck before making further changes.
That’s it! We hope this article was helpful.



