Support Library
SPF Record Expansion and Macros
How Email Validation follows SPF includes to count the 10-lookup limit and list authorized IP ranges, and why per-sender macros such as %{i} cannot be fully listed from DNS.
The short answer
An SPF record often lists only a few include terms, and each of those points at another record with more terms. Email Validation follows every include and redirect to the end, counts the DNS lookups a receiver would make against the limit of 10, and lists the IP ranges and mail services the policy authorizes.
Some providers publish includes with macros, such as %{i} for the sending IP. The name a receiver looks up then changes with every message, so no DNS query can return the full list of senders. For those, Email Validation shows the answer for a sample address and tests one address from each of a set of common mail services, and reports which ones the domain authorizes.
How expansion works
Email Validation reads the domain's SPF record and walks it the way a receiver would, term by term, under the rules in RFC 7208:
| Term | What the check does |
|---|---|
| ip4 and ip6 | Checks the address and prefix, and adds the range to the authorized list when it passes |
| include: | Fetches the named record and walks it too; counts one lookup |
| redirect= | Walked after every mechanism in the record, as receivers do; counts one lookup |
| a, mx and exists | Counted as lookups and listed as not resolved, since resolving them would take many more queries |
| ptr | Counted, and flagged as deprecated |
| all | Evaluation stops here; later terms are shown as never reached |
Order matters. A range that an earlier -ip4, ~ip4 or failing include already covers never passes, so it is left out of the authorized list. Ranges behind an include with a -, ~ or ? qualifier are not authorized either. The include tree on the card shows every record the check visited and a note on each term it skipped.
The 10-lookup limit
Receivers stop after 10 DNS-querying terms (include, a, mx, ptr, exists and redirect), counting nested includes, and return a permanent error for any message whose check needs more. They also allow only two lookups that return no answer (void lookups). Email Validation totals both across the whole tree and warns when either limit is passed.
The total counts every term, so it is a worst case. A sender matched by an early ip4 term passes before the later lookups happen. The senders that get the error are usually the ones matched late, or not at all.
To stay under the limit, remove includes for services you no longer use, replace a and mx terms with fixed ip4 or ip6 ranges where the addresses are stable, or send some mail from a subdomain with its own SPF record.
Per-sender macros
RFC 7208 section 7 lets a record build the name it looks up from parts of the message. The letters that matter here are:
| Macro | Expands to |
|---|---|
| %{i} | The sending IP address |
| %{s}, %{l}, %{o} | The envelope sender, its local part, and its domain |
| %{d} | The domain whose record is being checked |
| %{h} | The name the sending server gave in HELO or EHLO |
| %{ir} | The IP address with its parts reversed, as in reverse DNS |
Hosted SPF services use these so that one short include stands in for many senders. A record such as v=spf1 include:%{i}._ip.%{h}._ehlo.%{d}._spf.provider.example ~all asks the provider a different name for every sending IP. The provider answers with a small policy that covers that IP when it is allowed, and a default policy when it is not. This keeps the customer's record under the lookup limit, but it also means the list of senders lives only inside the provider's DNS server.
A macro that uses only %{d} gives the same name for every message, so Email Validation expands and walks it like a literal include, and reports its errors the same way.
How Email Validation reads a macro
For a macro that depends on the sender, the check makes two kinds of query:
| Query | What it shows |
|---|---|
| The sample address 192.0.2.1, an address reserved for documentation that no service sends from | The provider's default answer: what a sender it does not recognize gets. The includes behind this answer often name services that apply to every sender |
| One address from each common mail service, such as Microsoft 365, Google Workspace, Amazon SES, SendGrid, Mailchimp and others | Whether the domain authorizes that service. A service counts as matched only when its answer has a passing ip4 range that holds the tested address, and the include itself can pass |
The card then lists the services that matched, the ones that answered differently without a range holding the tested address (shown as not confirmed), the ones whose lookup failed (shown as could not be checked), and the rest as tested and not authorized.
These results speak for the tested addresses only. A matched service's answer is not added to the authorized ranges, because the provider could give a different answer for a neighboring address. Only the first sender-dependent macro in a record is tested, to stay inside the number of DNS queries one check can make.
Checking a macro by hand
Expand the macro yourself and look up the name. For the example record above, the domain example.com, a server that says EHLO mail.example.com, and a sending IP of 198.51.100.7:
| Command | What to look for |
|---|---|
| dig +short TXT example.com | The SPF record with the macro include |
| dig +short TXT 198.51.100.7._ip.mail.example.com._ehlo.example.com._spf.provider.example | The policy the provider returns for that IP; compare it with the answer for 192.0.2.1 |
The real test is still a message. Send one through the service and read the Authentication-Results header in the received copy, which shows the SPF result for that message's actual IP.
FAQ
Why does my provider's include not show any IP ranges?
Its include uses a macro such as %{i}, so the answer depends on the sending IP. Email Validation shows the answer for the sample address 192.0.2.1 and tests a set of common mail services, but it cannot list every address the provider would accept.
A service I use is not in the matched list. Is my SPF broken?
Not necessarily. Only one address per service is tested, and only a known set of services. Send a message through that service and read the Authentication-Results header to see the real SPF result.
Why are probe answers not counted toward the 10 lookups?
A receiver makes one lookup for a macro include per message, for that message's own IP. The extra service tests are this check's way of sampling, not lookups a receiver would make.
Why are a, mx and exists terms listed as not resolved?
Resolving every MX host would use many more DNS queries than the check can make. Those terms still authorize senders, so the card says how many were left unresolved instead of claiming a complete list.
Sources and further reading
- RFC 7208: Sender Policy Framework (SPF): section 4.6.4 sets the lookup limits and section 7 defines macros
- RFC 5737: IPv4 Address Blocks Reserved for Documentation: the source of the sample address
- RFC 8601: Message Header Field for Indicating Message Authentication Status: the Authentication-Results header
- Microsoft Learn: Set up SPF to identify valid email sources