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.
example.com. IN TXT "v=spf1 mx ip4:203.0.113.25 include:_spf.relay.example ~all"| Directive | What it allows |
|---|---|
mx | the 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 |
a | the address in the domain’s A record |
all | everyone else; placed last |
Qualifiers and results
| Sign | Result | Meaning |
|---|---|---|
+ (default) | pass | the server is allowed |
- | fail | the server is definitely not allowed |
~ | softfail | the server is probably not allowed |
? | neutral | the 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 apermerror, and SPF stops working. - A domain must have exactly one
v=spf1record: two records also give apermerror. - The standard discourages the
ptrdirective: it is slow and unreliable. - SPF checks the envelope, not the visible
Fromfield, 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 pagesVerified 9 Nov