SPF, DKIM and DMARC explained, with examples
Three DNS records decide whether other mail servers trust your email. This guide shows what each one does, how to write it and how to roll them out without losing real mail.
What each record does
| Record | Question it answers |
|---|---|
| SPF | Is this server allowed to send mail for this domain? |
| DKIM | Was this message signed by the domain, and is it unchanged? |
| DMARC | What should happen if SPF and DKIM do not line up, and where do reports go? |
SPF: who may send
One TXT record at the domain apex. List your sending servers and services, then end with a policy.
example.com. TXT "v=spf1 ip4:203.0.113.10 include:_spf.mailprovider.example -all"
-all means reject everything not listed. ~all means soft-fail, which is common while you are still finding senders.
DKIM: a signature on every message
Your mail server signs messages with a private key. You publish the matching public key in DNS under a selector name.
sel1._domainkey.example.com. TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqh..."
Your mail provider tells you the selector and the value. Publish exactly what they give you.
DMARC: the policy and the reports
Publish at _dmarc. Start with monitoring only, so you can see who sends as your domain.
_dmarc.example.com. TXT "v=DMARC1; p=none; rua=mailto:[email protected]"
Read the reports for a few weeks. When all legitimate senders pass, move to p=quarantine, then p=reject.
Check your records
With dig:
dig +short TXT example.com dig +short TXT _dmarc.example.com dig +short TXT sel1._domainkey.example.com
Then send a test message to a mailbox you control and read the original headers. Look for Authentication-Results with spf=pass, dkim=pass and dmarc=pass.
Common mistakes
- Two SPF records instead of one merged record
- More than ten DNS lookups in SPF (too many
includeentries) - Forgetting a sender such as a newsletter or invoicing tool
- Jumping straight to
p=rejectwithout reading reports - Publishing a DKIM key with a line break or missing characters
Questions
Do I need all three?
Yes. Large mailbox providers now expect SPF and DKIM, and DMARC tells them what to do with mail that fails.
Why does my mail still go to spam?
Authentication is necessary but not sufficient. Sending reputation, content and list quality matter too.
More guides
Ubuntu server hardening checklist
A step-by-step Ubuntu server hardening checklist: key-only SSH, UFW firewall, automatic security updates, fail2ban and how to verify each step.
Read the guide →How to migrate a website to a new server without downtime
A practical website migration plan: inventory, copy with rsync and mysqldump, test before DNS changes, lower the TTL, switch at a quiet hour, keep a rollback.
Read the guide →The 3-2-1 backup rule for servers, and how to test your restores
How to apply the 3-2-1 backup rule to a server: what to back up, encryption, off-server copies, retention, a simple nightly job and a restore test checklist.
Read the guide →Want this done for you?
We set up and check all of this on client servers, with a backup first and a written record.