Sender setup
Mailgun sending domains: SPF, DKIM and DMARC explained
Mailgun is an email delivery service aimed at developers, and a website or app that uses it sends from your domain through Mailgun's servers. Developers often set it up quickly and leave the DNS half finished, which is when mail starts landing in spam.
By Kyle Deligny, Titanos, Brisbane. Last reviewed 1 December 2026. General information, not legal advice.
This page is for the business owner or IT provider who inherited that setup. It describes what a complete configuration looks like without quoting values that belong in your dashboard.
Why a subdomain is the usual choice
Mailgun's own onboarding encourages a sending subdomain, such as one named for the service, rather than the root domain. That keeps application mail separate from staff mailboxes, so a problem with one does not drag down the other.
It also keeps SPF tidy. The root domain's SPF record stays focused on your mailbox provider, while the subdomain publishes its own record for Mailgun alone.
The records, by job
A sending domain in Mailgun generally needs a record authorising Mailgun's servers, a DKIM public key published as a TXT record, and optionally a tracking entry for click and open links. Receiving mail through Mailgun additionally needs mail exchange records.
Because the DKIM key and its selector are unique to the domain you add, copy them from the domain screen. Our advice is not to reuse values from another Mailgun domain or from a forum post.
| Job | Typical record type | Source of the value |
|---|---|---|
| Authorise sending servers | TXT, SPF | Dashboard domain screen |
| Sign messages | TXT, DKIM | Dashboard domain screen |
| Track links | CNAME | Dashboard domain screen |
| Receive mail, if used | MX | Dashboard domain screen |
Making DMARC pass
DMARC needs either SPF or DKIM to pass in alignment with the From domain. When the From address uses your subdomain and the DKIM key sits on that subdomain, alignment holds. If the From address is on the root domain but Mailgun signs for a subdomain, relaxed alignment under RFC 7489 usually still counts, though a strict policy would not.
Publish the DMARC record on the organisational domain, and use the sp tag if you want a different policy for subdomains. See our guide to the subdomain policy tag.
Developer handover notes
Ask the developer who created the Mailgun account for the domain name used, the region the account is in, and where the API key is stored. The region affects which servers appear in your records, so it is worth knowing before anyone edits DNS.
Also ask which parts of the application send mail. Password resets, order receipts and contact form notifications are often separate code paths, and each may use a different From address. Every one of those addresses needs to sit on a domain that you have authenticated.
Finally, keep the Mailgun records documented next to the application's deployment notes. Teams often rebuild a website and forget that DNS entries for email were never part of the code, so the next developer has nothing to compare against.
Typical failures
The usual faults are a missing DKIM record because only SPF was added, two SPF records on one name, and an application that sends from a different address than the one that was authenticated.
Check the From address the application actually uses. A developer test address on a domain you never set up in Mailgun will fail every check regardless of how tidy the rest is.
Mailgun checklist for a new sending domain
- Choose the subdomain you will send from.
- Add it as a domain in Mailgun.
- Copy the SPF, DKIM and tracking entries as shown.
- Publish them under the subdomain, not the root.
- Add receiving records only if you need inbound mail.
- Use the dashboard verify button after DNS settles.
- Confirm the application uses an address on that subdomain.
- Send a test to Gmail and read the headers.
- Publish or review DMARC on the organisational domain.
- Keep the records for as long as the domain sends.
Questions people ask
Should I use my root domain or a subdomain?
A subdomain is the more common and safer choice, because it isolates reputation. Either works if authenticated.
Do I copy the SPF value from this page?
No. Copy it from your Mailgun domain screen, which shows the right values for your region and account.
Why does Mailgun say verified but mail fails DMARC?
Verified means the records exist. DMARC also needs the From domain to align with the signing or return domain.
Does Mailgun handle unsubscribes for me?
Not automatically for every message type. Spam Act duties still apply to commercial messages you send.
Where to from here
The free privacy policy audit reads your published privacy policy against the Australian Privacy Principles and tells you what is missing. Privacy Care keeps your policy and your shopper data practices current for AU$149 a month, with a 3-month minimum. Would it be okay if we showed you what the audit finds? A no is welcome.
Sources
- RFC 7208, Sender Policy Framework (SPF)
- RFC 6376, DomainKeys Identified Mail (DKIM) signatures
- RFC 7489, DMARC
- Australian Cyber Security Centre, how to combat fake emails
- ACMA, avoid sending spam
General information, not legal advice. Laws and guidance change: check the linked primary sources and ask a qualified adviser about your own situation. Written by Kyle Deligny with AI assistance, last reviewed 1 December 2026. How we write and check: editorial policy.
