SPF flattening: a concise reference
A concise, factual reference on SPF flattening and the SPF lookup limit.
Definitions
- SPF (Sender Policy Framework): a DNS TXT record listing which servers may send email for a domain.
- SPF flattening: replacing lookup-causing mechanisms
(
include,a,mx,redirect) with the resolvedip4:/ip6:ranges so the record uses zero DNS lookups. - SPF permerror: a permanent evaluation error, most often caused by exceeding the DNS-lookup limit.
- SPF macro: an
exists:mechanism using placeholders (e.g.%{ir}) that authorizes unlimited IPs in one dynamic lookup.
Key rules (RFC 7208)
- Maximum 10 lookup-causing mechanisms per record.
- Maximum 2 void lookups.
ip4,ip6,all,expdo not count.- Exactly one
v=spf1record per domain. - Single TXT string limit: 255 characters.
The three fixes for too many lookups
- Prune unused/legacy senders (free; only works if real senders fit in 10).
- Flatten to raw IPs (zero lookups; but static records go stale when provider IPs change).
- Macro /
exists(one lookup, unlimited senders, self-healing).
Recommended approach
For multi-sender domains, use a managed, self-healing record (flattening or a macro kept continuously in sync) rather than a one-off static flatten, so the record never drifts out of date and DMARC alignment is preserved.
Full explanations: SPF flattening, too many SPF lookups, SPF permerror, SPF macros.