What SPF does
SPF (Sender Policy Framework) lets a domain owner publish a list of the servers allowed to send email for the domain. When a message arrives, the receiving server checks whether the server that delivered it is on the list.
It answers one narrow question: was this server allowed to send for this domain? It doesn't say whether the message is genuine, wanted or safe.
How a check works
- A server connects and announces the envelope sender, the Return-Path address where bounces go, for example
bounce@yourcompany.com. - The receiving server looks up the SPF record of that domain,
yourcompany.com, in DNS. - It works through the record from left to right, comparing the connecting IP address with each entry.
- The first match decides the result. If nothing matches, the
allat the end decides.
SPF checks the Return-Path, not the From address. The From address is what people see; the Return-Path is hidden. Many services use their own domain in the Return-Path, so SPF can pass for them while your name is in From. That's the gap DMARC closes. See the four addresses on a message.
Reading an SPF record
- v=spf1
- Marks the record as SPF. It must come first.
- include:
- Trusts the servers in another domain's SPF record, usually your email platform or a sending service. Microsoft 365 uses
include:spf.protection.outlook.com; Google Workspace usesinclude:_spf.google.com. - ip4: / ip6:
- Trusts a specific IP address or range.
- a / mx
- Trusts the servers in the domain's A or MX records.
- -all
- Everything else fails (hard fail).
~allmeans soft fail: suspicious, but not definite.?allmeans neutral, no opinion.
SPF results
| Result | What it means |
|---|---|
pass | The sending server is on the list. |
fail | It isn't, and the record ends in -all. |
softfail | It isn't, and the record ends in ~all. |
neutral | The record ends in ?all and makes no claim. |
none | The domain has no SPF record. |
temperror | A temporary DNS problem; a later check may pass. |
permerror | The record is broken: two SPF records, a syntax error or too many DNS lookups. |
For DMARC, only pass counts, and only when the domain that passed matches the From address.
Rules and limits
- One record per domain. Two records starting with
v=spf1cause a permanent error. - 10 DNS lookups at most. Every
include,a,mx,existsandredirectcounts, including the ones nested inside includes. See how to fix too many lookups. - No more than two empty lookups. Includes that point at nothing, often for services that shut down, also cause a permanent error.
- Every sending domain needs its own record, including subdomains. Domains that never send should publish
v=spf1 -all.
Why SPF isn't enough on its own
That's why SPF works as part of a set. DKIM adds a signature that survives forwarding, and DMARC ties both results to the From address people see.
Common questions
#Is SPF required?
In practice, yes. Gmail, Yahoo and Outlook.com expect SPF or DKIM from every sender, and SPF and DKIM from anyone sending in bulk. A domain without SPF is also easier to spoof.
#Where does the SPF record go?
In DNS, as a TXT record at the root of the domain, often entered as @. Each domain and subdomain that sends email needs its own.
#How long does an SPF change take?
Usually minutes to an hour, depending on the record's TTL at your DNS host. Some receivers cache the old record until the TTL runs out.