SPF: who may send mail for a domain
Updated
Email was designed with no way to check who a message really comes from. SPF (Sender Policy Framework) adds one check: the domain publishes, in a DNS TXT record, a list of the servers allowed to send its mail. A receiving server compares the address it received the message from with that list.
example.com. TXT "v=spf1 ip4:203.0.113.0/24 include:_spf.example.net -all"
Reading the record
- v=spf1 marks it as an SPF record
- ip4: and ip6: allow an address or range
- include: also allows whatever another domain's SPF record allows, such as your email provider
- a and mx allow the servers behind the domain's own A or MX records
- -all at the end means any other sender fails, ~all means it soft-fails (treat with suspicion), and ?all means no opinion
What SPF does and does not check
SPF checks the technical sender of a message, called the envelope sender, and not the From address people see in their mail program. A scammer can pass SPF with their own domain while showing yours in the From line. DMARC closes that gap by requiring the two to line up.
Common mistakes
- More than one SPF record on a domain, which makes the check fail. Merge them into one
- More than 10 DNS lookups caused by include, a, mx and similar terms, which also makes the check fail
- Forgetting a service that sends on your behalf, such as a newsletter tool
- Ending with +all, which allows everyone
- Forwarded mail often fails SPF, because it arrives from the forwarder's server. This is one reason to also use DKIM
Related
- DNS records explainedWhat the common DNS record types (A, AAAA, CNAME, MX, NS, SOA and TXT) do, and what a TTL means for changes.
- MX records and how email finds its wayHow MX records tell the world which servers accept mail for a domain, what the priority number means, and what a null MX is.
- DKIM: signing emailHow DKIM lets a domain sign its email so receivers can check it was not changed, and where the public key lives.
- DMARC: policy and reportsHow DMARC ties SPF and DKIM to the visible From address, tells receivers what to do with failures, and sends you reports.
- Email headers: what they are and how to find themThe hidden lines at the top of every email that show who sent it, the servers it passed through and whether it passed its checks.
- A domain health checklist: what to check and whyThe handful of public records that say whether a domain is set up sensibly for email, registration and DNS, and what each one protects against.
- Why a message gets flagged as spam or phishingThe things mail filters commonly react to, from failed sender checks to links that hide where they go, and which to fix first.
- Reading a bounce messageHow to read the code and the words in a non-delivery report, the difference between a temporary and a permanent failure, and what to try next.