An SPF record gets 10 DNS lookups. The receiver reaches the eleventh, stops, and returns permerror [1]. DMARC only counts an SPF result of pass [2], and Gmail and Outlook.com expect bulk mail to pass SPF [6][7].

The record can look fine for months. Receivers count lookups while they evaluate, left to right, and stop at the first match [1]. Mail from the services near the start of the record passes. Mail from the services near the end fails.

The short answer

permerror with too many DNS lookups means a receiver needed more than 10 DNS-querying terms to evaluate your SPF record. The terms include, a, mx, ptr, exists and redirect each cost one, and so does each of them inside the records you include [1]. Remove includes you no longer use, then move bulk senders to their own Return-Path subdomain.

What the error looks like

You will see it in one of these forms, depending on where you look.

In the headers of a delivered message, written by the receiving server in the Authentication-Results format of RFC 8601 [3]:

Authentication-Results: mx.example.net;
       spf=permerror smtp.mailfrom=example.com

From the Python SPF library pyspf, whose source builds the message from 'SPF Permanent Error: ' and 'Too many DNS lookups' [18]:

SPF Permanent Error: Too many DNS lookups
Exact text from source [18]

From Gmail, when you send in bulk and your mail fails SPF [6]:

421 4.7.27 Your email has been rate limited because SPF authentication didn't pass for this message. Gmail requires all bulk email senders to authenticate their email with SPF. …
550 5.7.27 This message was blocked because it didn't pass SPF authentication. Gmail requires bulk email senders to authenticate their email with SPF. …
Exact text from source [6]

RFC 7208 tells receivers that reject a message for a permerror during the SMTP session to use reply code 550 with enhanced status code 5.5.2 [1].

What counts toward the 10 DNS lookups?

Term Costs a lookup? Notes
include: Yes, 1 Plus every lookup inside the included record, all the way down.
a, mx Yes, 1 each mx has a second limit: it may look up addresses for at most 10 mail servers, or it returns permerror.
ptr Yes, 1 RFC 7208 says this mechanism SHOULD NOT be published.
exists: Yes, 1 Often written with macros, like exists:%{i}._spf.example.net.
redirect= Yes, 1 Plus the lookups in the record it points to.
ip4:, ip6:, all No Free.
exp= No Looked up only after a fail, outside the limit.

Source: RFC 7208, section 4.6.4 [1].

A second limit sits next to the first one. When a term queries DNS and gets no answer at all (an empty answer or NXDOMAIN), that is a void lookup. RFC 7208 says receivers SHOULD allow only two, and going over also produces permerror [1]. a: and mx: terms that name hosts you deleted use up this limit.

Why it fails for some mail and passes for the rest

Receivers that follow RFC 7208 count lookups during evaluation [1]. Evaluation runs left to right and stops at the first mechanism that matches [1]. If a message comes from an IP listed in your first include, the receiver never reaches lookup 11, and SPF passes. Microsoft describes the same behavior for Microsoft 365 [17].

With one record of 14 lookups, a message from an IP in the first include passes, and a message from an IP in the last include gets permerror. That is why the symptom often reads “invoices from the billing tool fail SPF, and normal mail is fine”. The billing tool’s include sits at the end of the record.

How to count your SPF lookups

You need the record and every record behind it. On macOS or Linux, dig does it:

dig +short TXT example.com | grep spf1

Take every include: and redirect= target from the answer and query it the same way. Keep going until you reach records with only ip4, ip6 and all. Add 1 for each include, a, mx, ptr, exists and redirect you met on the way.

On Windows, nslookup -type=TXT example.com returns the same TXT records.

A worked example. A company moved from Microsoft 365 to Google Workspace and added senders over time:

example.com.  TXT  "v=spf1 a mx include:_spf.google.com include:spf.protection.outlook.com include:sendgrid.net include:mailgun.org include:_spf.salesforce.com include:amazonses.com ~all"
Term Lookups
a 1
mx 1
include:_spf.google.com 1
include:spf.protection.outlook.com 1
include:sendgrid.net 2
include:mailgun.org 5
include:_spf.salesforce.com 2
include:amazonses.com 1
Total 14

Four over the limit. Mail from an IP that only matches after the tenth lookup gets permerror. So does mail that matches nothing at all, which means a forged message gets permerror instead of the fail or softfail your all asks for.

What common includes cost today

These totals come from querying each provider’s published SPF record with dig on 18 November 2026 [19]. Providers change their records without notice, so treat this as a snapshot and count your own.

Include Documented by Lookups it costs
_spf.google.com (Google Workspace) Google [12] 1
spf.protection.outlook.com (Microsoft 365) Microsoft [17] 1
amazonses.com (Amazon SES) Amazon [8] 1
spf.mtasv.net (Postmark) Postmark [10] 1
spf.messagingengine.com (Fastmail) Fastmail [13] 1
mail.zendesk.com (Zendesk) Zendesk [16] 1
_spf.mx.cloudflare.net (Cloudflare Email Routing) Cloudflare [15] 1
sendgrid.net (SendGrid) SendGrid [11] 2
_spf.salesforce.com (Salesforce) Google’s list of common senders [12] 2
mailgun.org (Mailgun) Mailgun [14] 5

Mailgun’s mailgun.org is the one to watch: it nests four more includes [19]. Salesforce’s record relies on an exists: macro [19], which matters if you plan to flatten (see below).

Fix it, cheapest step first

1. Delete includes for services you stopped using

In the example, the company left Microsoft 365. include:spf.protection.outlook.com authorizes Microsoft’s servers to send as example.com and does nothing else. Remove it.

Old includes can break SPF on their own. If the former provider stops publishing SPF at that name, RFC 7208 turns the include into permerror, even with fewer than 10 lookups [1].

2. Remove a and mx unless those hosts send mail

a authorizes the address example.com resolves to: your website, or the CDN in front of it. mx authorizes the addresses of your inbound mail servers. Hosted mailbox providers document an include for outgoing mail, such as include:_spf.google.com for Google Workspace [12] or include:spf.messagingengine.com for Fastmail [13], and those two setup guides do not ask for mx. If a server you run sends mail, list its address with ip4: or ip6:, which costs nothing [1].

3. Move bulk senders to their own Return-Path subdomain

SPF checks the domain in the envelope sender (MAIL FROM) [1], which the delivered message shows as Return-Path [20]. The visible From address is DMARC’s job [2]. Amazon SES, Postmark and SendGrid let you put that envelope sender on a subdomain of yours [8][9][11]. SPF for that mail is then checked on the subdomain’s own record, with its own budget of 10 lookups, and your root record no longer needs the vendor’s include.

Some of those includes never helped in the root record. Amazon SES sends from a subdomain of amazonses.com by default, and SPF passes there [8]. SendGrid documents include:sendgrid.net on its own em subdomain [11]. In both cases the include in your root record only spends lookups.

DMARC still passes on SPF, because its default relaxed alignment accepts bounce.example.com for a From address at example.com [2].

How three of the larger services do it:

  • Amazon SES: a custom MAIL FROM domain. You publish an MX record (10 feedback-smtp.<region>.amazonses.com) and a TXT record (v=spf1 include:amazonses.com ~all) on a subdomain such as bounce.example.com [8].
  • Postmark: a custom Return-Path. You add a CNAME from pm-bounces.example.com to pm.mtasv.net [9].
  • SendGrid: with automated security on, SendGrid gives you an em subdomain CNAME to add, and that CNAME carries SPF for its mail. You can also choose your own return-path name [11].

After steps 1 to 3 in the example (Microsoft 365 removed, a and mx removed, SES and SendGrid moved to subdomains):

example.com.         TXT    "v=spf1 include:_spf.google.com include:_spf.salesforce.com include:mailgun.org ~all"
bounce.example.com.  MX     10 feedback-smtp.eu-west-1.amazonses.com.
bounce.example.com.  TXT    "v=spf1 include:amazonses.com ~all"
em1234.example.com.  CNAME  u1234567.wl123.sendgrid.net.

Root record: 1 + 2 + 5 = 8 lookups, with room for two more. The SendGrid CNAME name and target here are placeholders in the shape SendGrid documents: copy the exact ones from your SendGrid dashboard [11].

4. Replace includes with addresses only for servers you control

If a server you run sends mail from a fixed address, ip4:203.0.113.25 costs nothing and never changes behind your back. Do this for your own servers. For a provider’s servers, prefer step 3.

5. Flatten, as a last resort

Flattening means replacing an include: with the IP ranges it resolves to today. It brings the count down at once, and it comes with three costs:

  • Your copy goes stale. When the provider adds an IP range, your flattened record does not change, and mail from the new range fails SPF. Someone or something has to flatten again on a schedule.
  • Some records cannot be flattened. Salesforce’s record relies on exists:%{i}._spf.mta.salesforce.com [19]. The %{i} macro is the connecting IP address, so the answer changes with each sending server, and DNS cannot expand it into a list of ranges [1].
  • The record grows. A single TXT string holds at most 255 characters, so long records are split into several quoted strings [1]. RFC 7208 also asks you to keep the whole SPF answer small enough to fit in 512 bytes [1].

Automated flattening services take on the first cost, and from then on a third party decides which IP addresses your SPF record authorizes. Try step 3 first.

Mistakes to avoid

  • Adding a second SPF record to make room. Two TXT records starting with v=spf1 on the same name are a permerror by themselves [1]. See two SPF records on one domain.
  • Counting only the includes you can see. mailgun.org looks like one lookup and costs five [19].
  • Keeping includes for vendors that use their own Return-Path. Postmark says that adding include:spf.mtasv.net to your root record “will do nothing for you” once its custom Return-Path is in place [10]. The include still costs a lookup.
  • Using ptr. It costs lookups, depends on reverse DNS you may not control, and RFC 7208 says not to publish it [1].
  • Leaving dead targets. A dead include: breaks SPF on its own (step 1). A dead a: or mx: target is a void lookup, and the third void lookup is a permerror [1].

Does it matter if DKIM passes?

For DMARC, one aligned pass is enough. A message with a valid DKIM signature from example.com passes DMARC even while SPF returns permerror [2]. If DMARC on your domain still sits at p=none, moving from p=none to p=reject is the next step after this fix.

Mailbox providers ask for more. Gmail requires bulk senders, those that send close to 5,000 messages or more to personal Gmail accounts in 24 hours, to set up both SPF and DKIM [4][5], and rate-limits or blocks bulk mail that fails SPF with the 4.7.27 and 5.7.27 codes above [6]. Outlook.com requires SPF and DKIM to pass for domains that send 5,000 or more messages to its consumer services, and rejects mail that falls short [7]:

550 5.7.515 Access denied, sending domain <domain> does not meet the required authentication level.
Exact text from source [7]

Fix the record even if DKIM covers you today. If you changed mail providers, old DKIM selectors can linger too: see remove old DKIM records. More SPF problems are on the SPF record page.

Check your SPF lookups now

The SPF checker walks your SPF record and every include in your browser, counts DNS lookups and void lookups, and shows which term crosses the limit.

Check your SPF lookups now

Runs in your browser. Your domain is not sent to this site or stored.

See it on a test domain

Check these names under badmail.dev to see this in a result, without checking your own domain.

All the test domains

Sources

  1. 1RFC 7208, Sender Policy Framework (SPF) for Authorizing Use of Domains in Email, Version 1. Sections 2.4, 3.3, 3.4, 4.5, 4.6.2, 4.6.4, 5.1, 5.2, 5.5, 5.7, 7.2, 8.7rfc-editor.org, IETF. Checked .
  2. 2RFC 9989, Domain-Based Message Authentication, Reporting, and Conformance (DMARC). Sections 3.2.10.1, 4.4.1, 4.4.2, 4.7 (aspf default r), 4.10.2rfc-editor.org, IETF. Checked .
  3. 3RFC 8601, Message Header Field for Indicating Message Authentication Status. Section 2.7.2rfc-editor.org, IETF. Checked .
  4. 4Email sender guidelinessupport.google.com, Google. Checked .
  5. 5Email sender guidelines FAQsupport.google.com, Google. Checked .
  6. 6Gmail SMTP errors and codesknowledge.workspace.google.com, Google. Checked .
  7. 7Fix NDR error “550 5.7.515” in Outlook.comsupport.microsoft.com, Microsoft. Checked .
  8. 8Using a custom MAIL FROM domaindocs.aws.amazon.com, Amazon Web Services. Checked .
  9. 9How do I add a custom return-path?postmarkapp.com, Postmark. Checked .
  10. 10How do I set up SPF for Postmark?postmarkapp.com, Postmark. Checked .
  11. 11Configure domain authenticationtwilio.com, Twilio SendGrid. Checked .
  12. 12Set up SPFknowledge.workspace.google.com, Google. Checked .
  13. 13Manual DNS configurationfastmail.help, Fastmail. Checked .
  14. 14Domain Verificationdocumentation.mailgun.com, Mailgun. Checked .
  15. 15Domain configuration (Email Routing records)developers.cloudflare.com, Cloudflare. Checked .
  16. 16Allowing Zendesk to send email on behalf of your email domainsupport.zendesk.com, Zendesk. Checked .
  17. 17Set up SPF to identify valid email sources for your custom cloud domainslearn.microsoft.com, Microsoft. Checked .
  18. 18pyspf source code, spf.py (strings ‘SPF Permanent Error: ’ and ‘Too many DNS lookups’; latest PyPI release 2.0.14)raw.githubusercontent.com, pyspf project. Checked .
  19. 19Measurement: dig 9.10.6 against 1.1.1.1, +short TXT on each include in the table and every include below it, n = 10 includes, 15 TXT records, 18 November 2026 at 11:53 CET, repeated at 12:34 CET, counted with the rules of RFC 7208 section 4.6.4rfc-editor.org, Measurement. Checked .
  20. 20RFC 5321, Simple Mail Transfer Protocol. Sections 4.4 and 6.1rfc-editor.org, IETF. Checked .