Mailgun
Mailgun DMARC setup: SPF, DKIM and DMARC records
Mailgun DMARC setup: add SPF and DKIM from your panel, verify the domain and collect reports while preserving your existing policy.
Check your current setup:
Mailgun DMARC setup has two halves. Mailgun gives you the SPF and DKIM records for your sending domain. You publish the DMARC record yourself at your DNS provider. SPF lists the servers allowed to send for a domain. DKIM adds a cryptographic signature to each message. DMARC tells receiving servers what to do when neither of them lines up with your From domain.
Before you start
Mailgun recommends that all customers send through a subdomain, such as mg.example.com. A subdomain has its own reputation, separate from your root domain. It also lets you add Mailgun’s MX records, which route incoming mail, without touching the mailbox on example.com.
Add the domain in the Mailgun Control Panel under Send → Sending → Domains, with Add new domain. Pick the Domain region (US or EU) at that step, because EU domains use different hosts. Then open the domain and find its records in Domain Verification & DNS. Copy the values from there, since the DKIM record is specific to your domain.
Step 1: Mailgun SPF record
On the domain you added to Mailgun (for example mg.example.com), create a TXT record with this value:
v=spf1 include:mailgun.org ~all
If that name already has an SPF record, add include:mailgun.org to it. A name must keep a single SPF record, so the result looks like v=spf1 include:_spf.example.com include:mailgun.org ~all. Today mailgun.org publishes both the US and EU ranges, so the same include covers either region.
SPF checks the envelope sender (the hidden MAIL FROM address, also called Return-Path), which Mailgun bases on your sending domain. DMARC counts SPF only when that domain aligns with your From address. Relaxed alignment, the DMARC default, treats mg.example.com and example.com as the same organization. SPF can therefore align whether you send as @example.com or @mg.example.com.
Step 2: Mailgun DKIM
Mailgun publishes DKIM in one of two ways, and the panel shows the one your domain uses. Both rely on a selector, the label before ._domainkey in the record name that tells receivers which key to fetch.
- TXT key. Mailgun gives you one TXT record. Copy its name and value exactly, because the selector varies per domain. Keys come in 1024 or 2048 bits. Mailgun describes 2048 as more secure and harder to set up.
- Automatic Sender Security. You add two CNAME records,
pdk1._domainkey.mg.example.comandpdk2._domainkey.mg.example.com. Each points to a Mailgun-hosted name that you copy from the panel. Mailgun’s manual showspdk1._domainkey.9d876.dkim1.mailgun.comas an example. Mailgun then generates two 2048-bit keys and rotates them every 120 days by default. You can change that interval, down to a minimum of 5 days.
Mailgun signs with your sending domain in d=, the domain field of the signature. A subdomain can also share the DKIM authority of its root domain when both are on the same Mailgun account. In that case the record can sit on the root domain, so use the name the panel shows. DKIM aligns under relaxed alignment either way.
Step 3: MX and tracking records
Mailgun’s verification table marks SPF, DKIM, a tracking CNAME and MX as required. DMARC itself reads only SPF and DKIM.
- MX:
mxa.mailgun.organdmxb.mailgun.org, priority 10. EU domains usemxa.eu.mailgun.organdmxb.eu.mailgun.org. Mailgun needs these to receive mail on this name, and it tracks delayed bounces only when they point to Mailgun. If the same name already receives mail elsewhere, Mailgun’s FAQ says not to point that name’s MX records to Mailgun. - Tracking CNAME:
email.mg.example.com→mailgun.org(EU domains:eu.mailgun.org). It powers open, click and unsubscribe tracking. Theemailprefix is the default and you can change it.
Allow 24 to 48 hours for DNS to propagate. Mailgun checks automatically, or you can click Verify DNS settings under Domain Settings. A verified domain shows a green Verified badge.
Step 4: DMARC record
Mailgun’s verification records do not include DMARC. If _dmarc already exists on that name, edit that record and add your reporting address to its rua tag instead of creating a second one. When a name has more than one DMARC record, receivers discard them all and the domain has no policy. Keep the current p= value. If it is already quarantine or reject, confirm that Mailgun mail aligns before you send real traffic.
Create it at your DNS provider, as a TXT record named _dmarc on your root domain:
Use this starter value only if no DMARC policy exists at this name. Otherwise edit the existing record, preserving its p=, alignment settings and report addresses; add your monitored rua destination there. Never create a second policy record.
v=DMARC1; p=none; rua=mailto:dmarc@example.com
p=none only monitors. Replace the rua address, where receivers send aggregate reports, with the reporting address DMARC Pulse gives you for this domain.
A receiver looks up _dmarc at the From domain first. If there is none, it walks up the DNS tree, so _dmarc.example.com also covers mg.example.com unless the subdomain has its own record. Under default relaxed alignment (r), mg.example.com can align with example.com. Preserve any existing adkim and aspf settings; strict alignment requires exact domains, as explained below.
Step 5: Check, then enforce
Send a test message through Mailgun and paste its headers into the Email Header Analyzer. Look for spf=pass, dkim=pass with your domain in header.d=, and dmarc=pass. Mailgun says it dual-signs many customers’ messages, with a platform domain and your subdomain. Only the signature with your domain can align, so check that one. The DMARC Checker confirms the record is live.
Preserve the existing policy, alignment settings and report destinations when adding Mailgun. Use p=none only for a first policy. Review reports for every legitimate sender before considering quarantine. Reject is an optional, separate decision: mailing lists and forwarding can break authentication for legitimate messages, and each receiver decides delivery.
Common problems
- The domain stays Unverified. DNS can take 24 to 48 hours. Check the name your DNS panel saved. If it appends your domain automatically, enter only the part before it, such as
mg. - Extra DKIM keys show Unverified. Mailgun can list several keys, for example after a rotation or when manually added keys remain after you enable Automatic Sender Security. Only the key your domain's configuration requires must be correct in DNS. With Automatic Sender Security, keep both CNAME records from Step 2 in place.
- A 2048-bit DKIM key will not save. Some DNS providers require splitting the value into two parts. Use the DKIM Checker with your selector to confirm the published key.
- Two SPF records on one name. Merge them into one. Two records make SPF return
permerror. - Too many SPF lookups. SPF allows 10 DNS lookups.
include:mailgun.orguses 5 today:mailgun.org,_spf.mailgun.org,_spf.eu.mailgun.org,_spf1.mailgun.organd_spf2.mailgun.org. A dedicated subdomain keeps Mailgun out of the count on your root SPF record. - Mailgun’s MX on a name that already receives mail. Several MX servers may serve one name, but replacing its MX records with Mailgun can reroute mailbox delivery. Keep the current MX or use a dedicated unused subdomain. Use a subdomain, or leave Mailgun’s MX out.
- DMARC fails while SPF and DKIM pass. The From domain must share its organizational domain (the registered name, such as
example.com) with the domain Mailgun signs for. Sending from another domain throughmg.example.comwill not align, so add that domain to Mailgun too. With strict alignment (adkim=sandaspf=s) the domains must match exactly, so a message sent as@example.comthroughmg.example.comfails both checks unless the DKIM signature uses your root domain. - Messages show “sent via Mailgun.org”. The domain is not verified. Mailgun also limits unverified domains to 300 emails per day.
- Outlook bounces a message whose DKIM passes elsewhere. Mailgun reports that DKIM can pass at Gmail or in DMARC reports and still show as failed at Microsoft. The error reads
550 5.7.515 Access denied, sending domain DOMAIN.TLD doesn't meet the required authentication level.In a June 2025 post, Mailgun said Microsoft may apply stricter alignment than DMARC requires, and described this as unconfirmed. If the bounces persist, it suggests asking its support team about signing with your root domain. - EU domain with US hosts. Copy the MX and tracking values your panel shows for the region you chose.