Skip to content

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

Check a domain's SPF record