Sender Policy Framework (SPF)
The Sender Policy Framework (SPF) is a DNS record in which a domain owner publishes the list of servers permitted to send mail using that domain. A receiving server compares the IP address that is connecting against that list and can reject, or downgrade, mail from anywhere else.
SPF is defined in RFC 7208. It is one of the three sender authentication mechanisms, alongside DKIM and DMARC, and it is the oldest and the most brittle of them.
What does an SPF record look like?
An SPF record is a TXT record published at the domain itself:
$ dig +short TXT example.com
"v=spf1 mx a:mail.example.com include:_spf.provider.example -all"
Read left to right, that says: mail is legitimate if it comes from a host listed
in the domain’s MX records, or from mail.example.com, or from anything the
provider’s own SPF record permits — and nothing else is.
A domain must publish exactly one SPF record. Two v=spf1 TXT records is a
permanent error, and the result is that authentication fails for everything.
Which mechanisms and qualifiers exist?
| Mechanism | Matches |
|---|---|
ip4: / ip6: |
a literal address or CIDR range |
a |
the A/AAAA records of the domain, or of a named domain |
mx |
the hosts listed in the domain’s MX records |
include: |
everything another domain’s SPF record permits |
all |
everything; always the last mechanism |
Each mechanism carries a qualifier that determines the result when it matches:
+pass (the default, somxand+mxare identical)-fail — the receiver is invited to reject~softfail — accept, but mark as suspicious?neutral — no statement at all
-all and ~all are the two endings worth using. ?all and a missing all
say nothing, which makes the whole record decorative.
What is the ten lookup limit?
SPF evaluation may perform at most ten DNS lookups. Every include:, a, mx,
ptr and redirect counts, and so does everything inside an included record.
Exceeding the limit produces a permerror, which most receivers treat as an
authentication failure.
This is the single most common way SPF breaks in practice. Each added SaaS
vendor — a newsletter tool, a ticketing system, a CRM — contributes
its own include:, and nothing warns you when the eleventh lookup pushes the
record over. Check it after every change:
$ dig +short TXT example.com
"v=spf1 include:_spf.provider.example include:sendgrid.net include:_spf.crm.example -all"
The usual remedies are removing vendors you no longer use, replacing a nested
include: with the ip4: ranges it resolves to, or “flattening” the record with
tooling that regenerates it when the upstream ranges change.
Why does SPF break on forwarding?
SPF authenticates the envelope sender against the connecting IP address. When a message is forwarded — by a university alias, a role address, or a user’s own “send a copy to my other mailbox” rule — the forwarder connects to the final destination from its own IP, which is not in the original domain’s SPF record. SPF fails, through no fault of anyone involved.
Two things mitigate this. Sender Rewriting Scheme (SRS) has the forwarder rewrite the envelope sender into its own domain so that SPF is evaluated against the forwarder instead. And DMARC treats a message as authenticated if either SPF or DKIM passes, so a valid DKIM signature survives the forward and keeps the message aligned.
What SPF does not do
SPF checks the envelope sender (MAIL FROM), not the From: header the
recipient actually sees. A message can pass SPF perfectly while displaying any
From: address at all — which is exactly how a great deal of
phishing authenticates cleanly.
Closing that gap is the job of
DMARC,
which requires the domain SPF authenticated to align with the domain in the
From: header. SPF on its own is a necessary component, not a defence.
What should you publish?
- One record, ending in
-allonce you are confident the list is complete, or~allwhile you are still finding senders. - A record for every domain you own, including ones that never send mail. For
those,
v=spf1 -allstates clearly that nothing is authorised. - No
ptrmechanism — it is deprecated, slow, and treated as unreliable. - A review whenever you add or remove a sending service, with a lookup count check afterwards.
Related reading
Howto block Google Groups spam in Rspamd is a useful demonstration of the limits of SPF: the messages pass SPF, DKIM and DMARC cleanly, because they genuinely are sent by Google. Authentication proves who handed the message over, not whether you wanted it.