Learn
What is SPF in Email? How an SPF Check Works
What is SPF in email? A DNS record listing the servers allowed to send for your domain. How the check works, an example record and common mistakes.
What it is
SPF (Sender Policy Framework) is an email authentication method that lets a domain list, in DNS, the servers allowed to send mail using its name. What is SPF used for? A receiving server compares the IP address delivering a message with that list and determines whether the server was authorized.
What is an SPF record for email?
An SPF record is a DNS TXT record that starts with v=spf1. Mechanisms (tests against the sending server) follow, normally closed by all for everything not matched earlier. A name can have only one SPF record, and subdomains do not inherit it. The SPF record syntax reference covers each mechanism.
How an SPF check works
- The sending server names an envelope sender with the SMTP
MAIL FROMcommand. Bounces go to that address. Readers do not see it, and it can differ from the visible From address. - The receiving server takes the domain of that address and looks up its TXT records in DNS, keeping the one that starts with
v=spf1. - It tests the sending IP address against the mechanisms from left to right and stops at the first match.
- The qualifier on that mechanism sets the result:
+givespass(the default with no sign),-givesfail,~givessoftfailand?givesneutral. With no match and noredirect, the result isneutral. - The receiver applies its own policy and can record the result in the message header.
The other possible results are none (no record or no usable domain), temperror (a temporary error, generally in DNS) and permerror (a record that cannot be interpreted). RFC 7208 sets no comprehensive rule for handling each result and leaves fail to local policy. It does say a neutral result must be treated like none, and that a softfail alone should not cause rejection. See how fail and softfail differ.
What SPF does not cover
SPF checks the envelope domain, so the From address people read can still be forged. RFC 7208 warns that a sender can pass SPF with its own domain and list a different identity in the header. DMARC, the policy built on SPF and DKIM, counts the MAIL FROM check only when that domain aligns with the From domain.
Forwarding is the other limit. SPF looks at the last sending server, so mail relayed with its original MAIL FROM usually fails. DKIM (a signature on the message) generally stays valid in that case.
Do you need an SPF record?
Google and Yahoo require SPF or DKIM from everyone sending to personal Gmail accounts and Yahoo mailboxes, and both from bulk senders. Google's FAQ defines a bulk sender as one sending close to 5,000 messages or more to personal Gmail accounts within 24 hours. Microsoft requires domains sending more than 5,000 emails a day to Outlook.com, Hotmail and Live addresses to pass SPF and DKIM and to publish a DMARC record.
Example
A company sends staff mail through Google Workspace and invoices from its own server at 203.0.113.25. It publishes one TXT record at example.com:
v=spf1 ip4:203.0.113.25 include:_spf.google.com ~all
include:_spf.google.com is the value Google publishes for Workspace. Here is what a receiver concludes when the MAIL FROM domain is example.com:
| Mail delivered by | Term that matches | Result |
|---|---|---|
203.0.113.25 |
ip4:203.0.113.25 |
pass |
| A server in Google's SPF record | include:_spf.google.com |
pass |
198.51.100.7 |
~all |
softfail |
RFC 7208 recommends recording the result in the message header, in forms such as this one:
Authentication-Results: myhost.example.org; spf=pass
smtp.mailfrom=example.com
To draft a record for your own senders, use the SPF generator.
Common mistakes
- Adding a second
v=spf1record. Two records on one name returnpermerroron every check. To add a sender, edit the record you have. Merge duplicates into one and keep every sender. - Moving to
-alltoo early. Caution: any server you forgot getsfail, and receivers may reject its mail. RFC 9989, the current DMARC specification, warns that this can happen before DMARC runs. Even a message with an aligned DKIM signature can be refused, and it will not appear in DMARC aggregate reports. First, keep~all, publish a DMARC record atp=nonewith aruaaddress, and review the aggregate reports until you have seen every real sender. - Going past 10 DNS lookups.
include,a,mx,ptr,existsandredirectcount, even inside included records. Past 10, the result ispermerror. See how to fix too many lookups. - Adding
include:for a service that uses its own envelope domain. Receivers check theMAIL FROMdomain, so thatinclude:is never read for the service's mail and SPF cannot align with your From domain. Where the service allows it, use aMAIL FROMon your domain or sign with DKIM for your domain. Before removing one, check theReturn-Pathof a message from that service: if it shows your domain, theinclude:is in use.