SPF, DKIM and DMARC explained
Three DNS records decide whether somebody else can send mail that appears to come from your domain. Here is what each does and the order to set them up.
Updated
The problem they solve
Email was designed without a check on the sender. Anyone can put your domain in the From line. SPF, DKIM and DMARC are how a receiving mail server tells your real mail from a forgery, and how you tell it what to do with the forgeries.
Since 2024 Gmail and Yahoo also require all three from anyone sending them mail in bulk, and mail from a domain without them is more likely to be filed as spam whatever the volume.
SPF: which servers may send
SPF is a TXT record on the domain that lists the servers allowed to send its mail.
example.com. TXT "v=spf1 include:_spf.google.com include:sendgrid.net -all"
- One SPF record per domain. Two records is a permanent error, and the check fails for every message.
- At most ten DNS lookups, counting every
include,a,mxandredirect, and the ones nested inside them. Past ten the record fails for everyone. - End with
-all(reject the rest) or~all(mark the rest as suspicious).+allallows the whole internet and is worse than no record. - The
ptrmechanism is deprecated. Remove it.
DKIM: a signature on each message
The sending service signs every message with a private key. The matching public key is published in DNS under a selector, and the receiver uses it to confirm the message was not altered and really came from a holder of that key.
selector1._domainkey.example.com. TXT "v=DKIM1; k=rsa; p=MIIBIjANBg..."
Use 2048-bit RSA keys, which every receiver can verify, and turn DKIM on in every service that sends as the domain: the mailbox provider, the newsletter tool, the invoicing system, the CRM.
DMARC: what to do with a failure
DMARC ties the other two to the address the reader actually sees. A message passes when SPF or DKIM passes for a domain that matches the From line. The record also says what a receiver should do with mail that fails, and where to send reports.
_dmarc.example.com. TXT "v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com"
p=noneonly watches. It is the right first step and the wrong place to stop: it does not block a single forged message.p=quarantinesends failures to spam.p=rejectrefuses them.ruais where the daily summary reports go. Without it you are changing policy blind.sp=sets the policy for subdomains, which otherwise inheritp.
The order that works
- List every service that sends mail as the domain. This is the step that gets skipped.
- Publish SPF covering them, and turn on DKIM in each one.
- Publish DMARC with
p=noneand aruaaddress. - Read the reports for two to four weeks. Fix the legitimate senders that fail.
- Move to
p=quarantine, then top=reject.
A domain that sends no mail
A parked domain, or one used only for a website, is a favourite for spoofing because nobody is watching it. Say explicitly that it sends nothing:
example.com. TXT "v=spf1 -all" _dmarc.example.com. TXT "v=DMARC1; p=reject" example.com. MX 0 .
Common mistakes
- A second SPF record added by a new vendor's setup guide.
- More than ten lookups after years of adding
includes. - DMARC left at
p=nonefor good. - A newsletter or billing tool that was never given DKIM, so its mail fails the day the policy tightens.
- Forgetting subdomains that send, such as
mail.orbilling..
After the basics
MTA-STS and TLS reporting ask other servers to deliver to you only over encrypted connections and to tell you when they cannot. BIMI shows your logo beside your mail in some inboxes, and requires DMARC at quarantine or reject first.
An OpSniper scan reads all of these records and judges the policy, not just its presence. Scan a domain free, or see everything a scan checks.