Bookmarks

SPF — Sender Policy Framework

A TXT record in a domain’s DNS that lists the servers allowed to send mail on behalf of that domain.

Also: SPF record, SPF policy

checked 9 Nov

All terms

The email protocol does not check who is named as the sender, so a message can be sent from someone else’s domain. SPF lets a domain owner publish a list of authorised senders in advance, and lets the receiving server check the IP address the message came from against it.

How the check works

The receiver takes the domain from the envelope address (MAIL FROM), or from the HELO/EHLO greeting if that is empty, requests that domain’s TXT record and looks for the string that starts with v=spf1. It then walks through the directives from left to right until one matches the address of the sending server. The result is set by the sign in front of the directive (the qualifier) or, if nothing matched, by the default outcome, neutral.

dns
example.com. IN TXT "v=spf1 mx ip4:203.0.113.25 include:_spf.relay.example ~all"
DirectiveWhat it allows
mxthe servers listed in the domain’s MX records
ip4: and ip6:a specific address or network
include:the servers listed in another domain’s SPF, for example a mail service
athe address in the domain’s A record
alleveryone else; placed last

Qualifiers and results

SignResultMeaning
+ (default)passthe server is allowed
-failthe server is definitely not allowed
~softfailthe server is probably not allowed
?neutralthe owner makes no claim

So -all at the end of a record is a strict ban on everyone else, and ~all is a soft one. SPF does not reject a message by itself: the receiver applies the result according to its own policy, most often together with DMARC.

Limitations

  • Evaluating a record may involve at most 10 DNS lookups (include, a, mx, ptr, exists, redirect); more than that is a permerror, and SPF stops working.
  • A domain must have exactly one v=spf1 record: two records also give a permerror.
  • The standard discourages the ptr directive: it is slow and unreliable.
  • SPF checks the envelope, not the visible From field, and breaks when a message is forwarded: the forwarding server’s address is not listed in the sender’s SPF.

The current version of the protocol is described in RFC 7208 (Scott Kitterman, April 2014), which replaced RFC 4408.

Sources

the term is written from these pages

Verified 9 Nov

Not to be confused with

what it is mixed up with and how it differs

In depth in the references

where the topic is covered in detail