Home › Guides › SPF, DKIM and DMARC
SPF, DKIM and DMARC Explained with Example Records
SPF, DKIM and DMARC are three DNS TXT records that tell receiving mail servers whether an email claiming to come from your domain is real. Without them, your mail is more likely to land in spam, and anyone can send mail that looks like it comes from you. Gmail and Yahoo now require all three from bulk senders. This guide explains what each record does, shows a working example of each, and lists the mistakes that break them. You can paste any of these records into the DNS record validator to check the syntax.
How the three fit together
- SPF lists which servers are allowed to send mail for your domain.
- DKIM adds a cryptographic signature to each message, and publishes the public key in DNS so receivers can verify it.
- DMARC tells receivers what to do when a message fails those checks, and where to send reports. It also requires the domain the reader sees in the From: line to match (align with) the domain that passed SPF or DKIM.
SPF
An SPF record is a TXT record on the domain itself:
example.com. TXT "v=spf1 include:_spf.google.com include:sendgrid.net ip4:203.0.113.10 -all"
v=spf1must come first.include:pulls in another domain's list, for example your email provider or newsletter service.ip4:andip6:list your own servers' addresses or ranges.- The final
allsays what happens to everything else:-allfail,~allsoft fail (accept but mark as suspicious),?allneutral. Avoid+all, which lets anyone send as you.
SPF mistakes that break delivery
- Two SPF records. A domain may have only one TXT record starting with
v=spf1. Two records make SPF return a permanent error. Merge them into one. - More than 10 DNS lookups. Each
include,a,mx,existsandredirectcosts a lookup, including the lookups inside the included records. Past 10, SPF fails (RFC 7208). Remove services you no longer use before adding new ones. - SPF checks the envelope sender, not the From: line. The address readers see can differ, which is why SPF alone doesn't stop spoofing. DMARC closes that gap.
DKIM
Your mail server or provider signs each message with a private key. The public key goes in a TXT record under a selector, a name the provider gives you:
google._domainkey.example.com. TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA..."
- The record name is
<selector>._domainkey.<your domain>. The selector (googlehere) appears in each signed message'sDKIM-Signatureheader ass=google. p=holds the public key. An emptyp=means the key has been revoked.- Each sending service gets its own selector, so you can have several DKIM records at once.
- Use 2048-bit RSA keys where your DNS host allows them. Long keys may have to be split into several quoted strings in one TXT record, which is normal.
Most of the time you don't write a DKIM record by hand; you copy it from your email provider's admin panel. The common mistake is publishing it at the wrong name, for example adding the domain twice (google._domainkey.example.com.example.com) because the DNS panel already appends it.
DMARC
DMARC lives at _dmarc. plus your domain:
_dmarc.example.com. TXT "v=DMARC1; p=none; rua=mailto:[email protected]; adkim=r; aspf=r"
p=is the policy for mail that fails:none(only report),quarantine(usually send to spam) orreject.rua=is where receivers send daily aggregate reports. Read them before you tighten the policy; they show every service sending as your domain, including ones you forgot.adkimandaspfset alignment to relaxed (r, subdomains match) or strict (s, exact match). Relaxed is the default and fits most setups.
A safe rollout
- Publish SPF and DKIM for every service that sends as your domain.
- Add DMARC with
p=noneand aruaaddress. Watch the reports for a few weeks. - Fix any legitimate sender that fails (usually a missing DKIM setup on a newsletter, CRM or billing tool).
- Move to
p=quarantine, thenp=rejectonce reports show only spoofed mail failing.
What Gmail and Yahoo require
Since February 2024, Google and Yahoo require anyone sending more than about 5,000 messages a day to their users to have SPF, DKIM and a DMARC record (p=none is enough), with the From: domain aligned with SPF or DKIM. They also require one-click unsubscribe for marketing mail and a low spam-complaint rate. Senders below that volume still need SPF or DKIM. Even a small personal domain benefits from all three, because they make your legitimate mail easier to trust.
Domains that never send mail
Parked or web-only domains are easy targets for spoofing because nobody watches them. Lock them down with:
example.net. TXT "v=spf1 -all"
_dmarc.example.net. TXT "v=DMARC1; p=reject;"
Checking your records
Look up what is published with dig TXT example.com, dig TXT _dmarc.example.com and dig TXT selector._domainkey.example.com (or nslookup -type=TXT on Windows). Paste each result into the DNS record validator, which checks the syntax against the RFCs and explains each part. To confirm a real message passed, open its full headers and look for spf=pass, dkim=pass and dmarc=pass in the Authentication-Results line.
Related tools
- DNS Record Validator: SPF, DKIM and DMARC syntax check with a plain-English breakdown.
- IP Subnet Calculator: work out the range an
ip4:CIDR block covers. - IPv6 Subnet Calculator: the same for
ip6:ranges.