What the message looks like
Authentication-Results: mx.example.net; spf=permerror (too many DNS lookups) smtp.mailfrom=newsletter@example.comCommon causes
- Too many
include:terms, usually one per service (Google Workspace, Microsoft 365, newsletter tool, CRM, helpdesk). The lookups inside each included record count too, so nested includes add up quickly. - Mechanisms
a,mx,ptrandexistsand the modifierredirecteach count as one lookup. A baremxcan pull in several more names.ip4,ip6andallcost nothing. - Old includes of services that no longer send mail are still in the record.
- The record grew unnoticed. A provider adds an include to its own record, or someone adds one more service, and the total tips from 10 to 11.
- Too many void lookups: names in the record that return no data or NXDOMAIN. More than two of them can also end in
permerror(RFC 7208 recommends this limit).
Check
- Current SPF record
- Terms at the top level that cost a lookup (nested includes come on top)
dig +short TXT example.com | tr -d '"' | grep -i 'v=spf1' | tr ' ' '\n' | grep -ciE '^[+?~-]?(include|a|mx|ptr|exists)([:/]|$)|^redirect=' - Look into an included record (example)
dig +short TXT _spf.google.com - Verdict of the receiver in the message header
grep -iE 'spf=|received-spf' message.eml
Fix
- Count exactly, including nested includes. The SPF checker on this site or any recursive SPF tester does it. Aim for 10 or less with a little reserve, because providers can change their own records.
- Remove includes of services that no longer send. The DMARC aggregate reports show who really sends for the domain.
- Replace
aandmxfor your own servers withip4:andip6:entries. They need no lookups. Do not useptr, it is slow and discouraged by the RFC. - Move mail streams to subdomains with their own SPF record, for example
news.example.comfor the newsletter tool. Each domain has its own limit of 10. Many providers allow a custom MAIL FROM or return-path domain for this. - Flattening replaces includes by the IP ranges behind them and needs no lookups. The trade-off: providers change their ranges without notice, so a static flattened record goes stale and legitimate mail starts to fail. Only flatten with automation that refreshes the record, and watch the size limits of a TXT record (255 characters per string, and the whole answer should stay small).
- Make sure every sender also signs with DKIM aligned to your domain. DMARC passes with an aligned DKIM signature alone, so a broken SPF then does not by itself cause DMARC failures.
Typical scenario
A company uses Microsoft 365 for mail, a newsletter tool, a CRM and a helpdesk system, each with an include: in the SPF record of the main domain. Since a fifth service was connected, newsletter messages show spf=permerror in the header and some recipients sort them into spam. At first glance there are only five includes, but the included records contain further ones. Counted in depth, the record comes to more than 10.
FAQ
Are there other reasons for an SPF permerror?
Yes. Two v=spf1 records on the same domain give a permerror, as do syntax errors and an unknown mechanism. The "too many DNS lookups" text is one case among them, so read the exact message in the header.
Does an SPF permerror make my mail bounce?
Not by itself. The receiver treats SPF as failed or broken and decides from the rest: DKIM, DMARC policy and reputation. With p=reject and no aligned DKIM it can mean rejection, otherwise the mail often lands in spam.
Do ip4 or ip6 count towards the limit?
No. ip4, ip6 and all need no DNS query and do not count. exp is not among the limited terms either. What counts is include, a, mx, ptr, exists and redirect.
How long may an SPF record be?
A single TXT string holds at most 255 characters, and longer records are split into several strings. In practice the whole DNS answer should stay small so that it transfers without problems. When flattening, that is the second limit next to the 10 lookups.
How often does a flattened record need to be refreshed?
That depends on the provider and cannot be said in general. Providers change their ranges without notice, so a tool should compare and update the record regularly and automatically. Flattening by hand once a year is not enough.