How to fix SPF too many DNS lookups

Cut the SPF record to ten or fewer DNS-querying terms, counting nested includes, so receivers stop returning permerror.

Last reviewed

Why it matters

SPF may use at most ten terms that need a DNS lookup; past that, receivers must return permerror. Many treat permerror as a failure, so mail relying on SPF for DMARC fails as if the domain had no SPF at all.

How to fix it

How lookups are counted: include, a, mx, ptr, exists and redirect each cost one, and so does every such term inside an included record: an include whose record holds three more includes costs four. ip4, ip6 and all cost nothing. The record now reads:

v=spf1 include:_spf.google.com ~all

Replace the highlighted values: v=spf1 include:_spf.google.com ~all with your current SPF record, example.com with your domain.

Any DNS host

  1. Remove includes for services that no longer send: an old newsletter tool, a previous host, a CRM the client dropped.

  2. Remove includes that do nothing. SPF checks the envelope sender (the return-path), not the From line. Send a test from each service and look at its Return-Path header: if it is the service's own domain, your include for it plays no part in SPF or DMARC, and that service needs DKIM with your domain instead. Read the service's own instructions before removing it.

  3. Replace a and mx with ip4:/ip6: where they point at a few stable addresses you control. Hosting panels often add a mx by default; if the web and mail servers do not send mail for the domain, delete them.

  4. Move bulk senders to a subdomain, for example news.example.com set as the newsletter's or CRM's sending domain, with its own SPF record and its own ten-lookup budget.

  5. Flatten only as a last resort: replacing an include with the addresses it resolves to today goes stale when the provider changes them, and that provider's mail then fails without warning. Never flatten Microsoft 365's include.

Write the result as one record: two SPF records are also a permerror. Start from the current record and remove terms rather than retyping it. The shape, with the services that remain:

v=spf1 ip4:203.0.113.10 include:_spf.google.com include:sendgrid.net ~all

Use a TTL of 3600. A record over 255 characters is split into several quoted strings; receivers join them with no space, so keep a space at the start of the next string where one belongs.

Sources: RFC 7208 §4.6.4, Microsoft: configure SPF.

Microsoft 365

Keep include:spf.protection.outlook.com and do not flatten it: Microsoft says its sending addresses change often. Microsoft's own ways to reduce lookups are replacing stable third-party includes with addresses, moving third-party senders to subdomains, and consolidating services.

Source: Microsoft: configure SPF.

Check that it worked

dig TXT example.com +short | grep spf1

Confirm there is exactly one v=spf1 line and re-count it with the free SPF checker. Wait out the old TTL, run the Owl Keeper Email authentication check again, and send a test from each remaining service to a Gmail or Outlook mailbox: Authentication-Results should show spf=pass.

Test it now with the free SPF checker. No account needed.

What can go wrong

  • Removing an include for a service that still sends breaks its SPF: harmless if it signs DKIM as your domain, harmful if it relies on SPF for DMARC.
  • Flattened records go stale when providers change their addresses.
  • It can look fine for some senders: receivers stop counting at the first match, so a record over the limit works for senders listed early and fails for the rest.
  • The next service puts you back over. Owl Keeper warns at exactly ten lookups so you see it coming.