Learn · 5 minute read
What is SPF, and how do you set it up?
SPF is a list, published in your DNS, of the servers allowed to send email as your domain. Receiving servers check it to decide whether a message that says it is from you really is.
What an SPF record looks like
An SPF record is a single TXT record at the root of your domain. It starts with v=spf1, lists who may send, and ends with a rule for everyone else:
v=spf1 include:_spf.google.com include:amazonses.com ~allinclude:_spf.google.comsays “whatever Google Workspace says is allowed, is allowed.” Each service you send through gives you an include like this.ip4:203.0.113.5allows one address of your own, if you run your own mail server.~allat the end says “anyone else is probably not me” (a soft fail).-allsays “definitely not me” (a hard fail). Never use+all: it allows the whole internet.
What SPF actually checks
SPF checks the envelope sender, also called the return-path or MAIL FROM, which is not the “From” address people see in their inbox. That is why SPF alone cannot stop someone forging your visible address. DMARC closes that gap by requiring the checked domain to match the visible one.
SPF also breaks when mail is forwarded, because the forwarding server is not on your list. This is normal, and it is one reason you also need DKIM, which survives forwarding.
The mistakes that break SPF
- Two SPF records. A domain must have exactly one. With two, receivers treat SPF as broken. Merge them into a single record.
- More than 10 DNS lookups. Every
include,a,mx,ptr,existsandredirectcounts, including the ones inside the records you include. Over 10, the whole record fails. Remove services you no longer use. - A service missing from the list. If you send through a newsletter tool or an email API and it is not in your SPF, its mail can fail.
- Using
ptr. It is slow and discouraged. - No
allat the end. Without it, the record says nothing about mail from other servers.
How to set it up
- List every service that sends email as your domain: your mailbox provider, your email API, your newsletter tool, your help desk.
- Find the SPF include each one tells you to use.
- Create one TXT record at your domain that starts with
v=spf1, has each include, and ends in~all. - Wait for DNS to update (often minutes, sometimes longer, depending on the record’s TTL), then check it. Run your domain through the free domain checker to see it.
Common questions
Do I need SPF if I already have DKIM?
Yes, set up both. DMARC passes when either one passes and lines up with your From domain, but mailbox providers expect to see both, and having both keeps your mail working when one of them breaks, such as SPF when a message is forwarded.
Should I end my SPF record with ~all or -all?
Start with ~all. It is safe while you make sure every sender is listed. Once you are certain the list is complete you can move to -all, though with DMARC in place the difference matters less.
Can I have two SPF records?
No. A domain must have exactly one SPF record. Two records make SPF fail. Combine them into one by merging the includes.
How long does an SPF change take?
As long as the record’s TTL: usually minutes to a few hours. Some resolvers cache longer, so allow up to a day before assuming something is wrong.
Keep reading
- What is DKIM, and how do you set it up?
- What is DMARC, and how do you roll it out safely?
- Why your emails go to spam, and how to fix it
SendSend is an email API that checks these records for you and tells you when a domain is verified. Get started free.