SPF (Sender Policy Framework) is a DNS TXT record that lists the servers allowed to send mail for your domain. A receiving server looks up the record for the domain in the envelope sender, compares the connecting IP address with it and decides to accept, flag or reject the message. Without SPF, anyone can send mail that appears to come from you. SPF is also one of the checks behind DMARC, which large mailbox providers now expect from every sender.
A record is a list of terms, read from left to right. The first term that matches the sending server decides the result.
| Term | Meaning |
|---|---|
v=spf1 | Marks the record as SPF. It always comes first. |
ip4:203.0.113.5, ip6:2001:db8::/32 | Allows an IP address or a range. Costs no DNS lookup. |
include:_spf.google.com | Also allows everything the other domain's SPF record allows. Costs a lookup, plus the lookups inside it. |
mx, a | Allows the servers in your MX records, or the address your domain points to. One lookup each. |
~all | Softfail: other senders are suspicious. Use -all to reject them. |
The limit of 10 DNS lookups
Receivers stop at 10 DNS lookups per check. Every include, a, mx, ptr, exists and redirect counts, and so does every one inside the records you include. Go over 10 and the result is a permanent error (permerror), which many receivers treat like a failed check. A few mail services in one record can add up faster than you expect, so the checker above counts the full chain. More than 2 lookups that return nothing (void lookups) is also an error.
If you are over the limit, drop services you no longer send from, replace an include with the ip4 and ip6 ranges it contains, or send mail from a subdomain with its own record.
Common SPF mistakes
- Two SPF records. A domain may have only one TXT record starting with
v=spf1. Merge them into one. +allor?all. Both let anyone send as your domain. End the record with~allor-all.- A typo in an include. An include that points to a name without an SPF record is a permanent error for the whole record.
- Forgetting a sender. With
-all, a newsletter tool or invoicing system that is not listed has its mail rejected. Start with~all, review your DMARC reports, then tighten.
SPF is stored as a TXT record at the root of your domain. With DNSense you can edit it at any provider from one table, and keep a backup of the zone before you change it.
