Skip to content
One-on-one deliverability consultationBook
Book a support call
  • There are no suggestions because the search field is empty.

Mailgun - SPF & DKIM Configuration

Learn how to configure SPF and DKIM records for Mailgun to authenticate your sending domain, improve deliverability, and prevent spoofing.

Cover illustration for Mailgun SPF and DKIM configuration with SPF and DKIM records and a deliverability chart

 ๐ŸŽง Prefer to listen? Hit play to hear this article read aloud.

How to configure SPF and DKIM records in Mailgun?

Supported Authentication Methods
โœ… SPF:
Supported
โœ… DKIM: Supported

First, Log in to your Mailgun account.

Sinch Mailgun login page asking for an email address, first step to configure SPF and DKIM records

From the left navigation menu, click in Sending โ†’ Domains. This is where you'll manage the domain used for sending emails.

Mailgun sidebar with Send menu and Domains option highlighted to add a sending domain
Add a subdomain to your account. When adding the domain, select a 2048-bit DKIM key length, as this is the recommended and most secure option.

Important: Always use a subdomain, not your root domain. Using a subdomain prevents Mailgun's MX records from conflicting with the MX records already configured on your primary domain.

Mailgun Add new domain form with the domain name entered and the 2048 DKIM key length selected


Mailgun โ€“ SPF Record Configuration

After adding your subdomain, Mailgun will generate an SPF record.

1. Copy the SPF record provided by Mailgun.
2. Open your DNS provider.
3. Add the SPF record to th
e subdomain you created.

Mailgun domain DNS records tab with unverified SPF and DKIM TXT records highlighted for manual setup

The example below shows how the record appears in Cloudflare.

Cloudflare DNS form adding the Mailgun SPF TXT record with include:mailgun.org for SPF configuration


Mailgun โ€“ DKIM Record Configuration

Next, configure your DKIM record.

1. Copy the DKIM record generated by Mailgun.
2. Publish it in your DNS zone using your DNS provider.

The example below shows how the record appears in Cloudflare. 

Cloudflare DNS form adding the Mailgun DKIM TXT record with the k=rsa public key for DKIM configuration


Configure the Additional DNS Records

In addition to SPF and DKIM, Mailgun requires a few extra DNS records to function correctly.

These include:
a) MX records:  Required for email routing.
b) Tracking CNAME record: Enables email open and click tracking.

Mailgun Receiving records showing two unverified MX records for the additional DNS records step

Tracking record:

Mailgun Tracking records with the unverified CNAME record needed for open and click tracking

Add the Tracking CNAME record to your DNS configuration. The example below shows how it should look in Cloudflare.

Cloudflare DNS form adding the Mailgun tracking CNAME record pointing to mailgun.org


Enable DMARC Reporting

Mailgun now supports DMARC reporting. To enable it, add Mailgun's RUA and RUF email addresses to your existing DMARC record, if you already have one for that subdomain.

Do not create a second DMARC record; each domain should have only one. Simply update the existing record with Mailgun's addresses.

Mailgun Authentication records showing the unconfigured DMARC TXT record to enable DMARC reporting


Verify Your DNS Records

Once all DNS records have been added, wait for DNS propagation.

When Mailgun detects the records successfully, each one will display a Verified status next to each record, confirming everything is active.

You can also click Check Status button at any time to verify whether your DNS records have been detected.

Mailgun DNS records with SPF, DKIM, MX and tracking CNAME all marked Verified after DNS propagation


Configuration Complete

Your Mailgun SPF and DKIM setup is now complete, and you're ready to send DMARC-compliant emails. Make sure your DMARC record has both aspf and adkim set to relaxed (rather than strict) for best compatibility.