How SPF works
Anyone can put your domain in the From line of an email. SPF is how a receiving server tells real mail from forged mail: it compares the server that delivered the message with the list you published.
You publish a record
A TXT record on your domain lists every service and IP address allowed to send for it.A message arrives
The receiving server notes the IP address of the server that delivered it.It looks up your record
It fetches the SPF record for the domain in the message’s return path.Pass or fail
If the IP is on the list, SPF passes. If not, it fails, and the message may be filtered or rejected.
Your receipt from Acme
From billing@acme.com
- Sent by
- Plunk
- SPF
- Pass
Urgent: verify your account
From billing@acme.com
- Sent by
- Unknown server
- SPF
- Fail
Reading an SPF record
An SPF record is one line of text. It starts with the version, lists the allowed senders, and ends with what to do about everyone else.
v=spf1 include:_spf.google.com include:sendgrid.net ip4:192.0.2.1 ~all| Part | What it means |
|---|---|
| v=spf1 | The SPF version. Every record starts with this. |
| include:sendgrid.net | Allow every server listed in another domain’s SPF record. This is how you add a provider. |
| ip4:192.0.2.1 | Allow one IPv4 address, or a range such as 192.0.2.0/24. |
| ip6:2001:db8::1 | Allow one IPv6 address or range. |
| a | Allow the IP addresses in the domain’s A record. |
| mx | Allow the servers in the domain’s MX records. |
| ~all | Soft fail: accept mail from anyone else, but mark it as suspicious. |
| -all | Hard fail: reject mail from anyone else. |
Why SPF matters
Stops spoofing
Forged mail from servers you did not list fails the check.Helps you reach the inbox
Gmail, Yahoo and Outlook expect bulk senders to pass SPF.Protects your domain
Phishing that uses your name is easier for inboxes to catch.Needed for DMARC
DMARC builds on SPF and DKIM results.
How to set up SPF
List everything that sends as you
Your mailbox provider, your product’s email service, your help desk, your newsletter tool.Collect each service’s include
Every provider documents the value to add.Value Service include:_spf.google.com Google Workspace include:spf.protection.outlook.com Microsoft 365 include:spf.useplunk.com Plunk Combine them into one record
v=spf1 include:_spf.google.com include:spf.useplunk.com ~allAdd it to your DNS
Create a TXT record at the root of your domain, usually written as @. Replace any SPF record that is already there rather than adding a second one.Check it
Run your domain through the SPF checker to confirm the record is valid and under the lookup limit.
Common mistakes
Two SPF records
A domain can only have one. With two, both are ignored and SPF fails. Merge them.Too many lookups
Each include adds at least one lookup. Past 10, every message fails.Forgetting a new tool
When you start sending from a new service, add it to the record the same day.Ending with +all
+alllets any server in the world pass. Use~allor-all.