What is SPF
SPF (Sender Policy Framework, RFC 7208) is a DNS TXT record that lists the servers allowed to send mail for a domain. A receiving server looks up the record for the domain in the envelope sender (the Return-Path) and checks whether the sending IP address is on the list.
The record is a list of mechanisms read from left to right: ip4 and ip6 for addresses, include for another domain's SPF record, a and mx for the domain's own hosts. The all mechanism at the end decides what happens to every other server.
Why it matters
Without SPF, any server can claim to send mail for your domain, and receivers have little to go on. SPF is also one of the two ways a message can pass DMARC, so a broken SPF record weakens your DMARC policy.
SPF fails quietly. A second record, a typo or one include too many turns the result into a permanent error, and receivers treat all your mail as unauthenticated. Mail often keeps flowing for a while, so the problem is noticed late.
What a correct record looks like
Publish exactly one TXT record at the domain apex. It starts with v=spf1 and ends with -all (reject other servers) or ~all (mark them as suspicious).
DNS record
example.com. TXT "v=spf1 ip4:192.0.2.10 include:_spf.google.com include:mailgun.org -all"
Each include, a, mx, ptr, exists and redirect costs one DNS lookup, and includes inside includes count too. The total must stay at 10 or fewer. ip4 and ip6 cost nothing.
Common problems
- More than one SPF record
- Receivers return a permanent error when a domain has two v=spf1 records. Merge all mechanisms into one record.
- More than 10 DNS lookups
- Every include adds lookups, often several. Remove services you no longer use, or replace includes with ip4 and ip6 ranges where the provider publishes them.
- +all or ?all at the end
- +all allows any server to send as your domain. ?all gives receivers no answer. End the record with -all or ~all.
- Syntax errors
- A missing space, an unknown mechanism or a typo in include: makes the whole record invalid.
- Record on the wrong name
- SPF is checked for the envelope sender domain. If you send from a subdomain such as mail.example.com, that subdomain needs its own record.