Your SPF record probably started small:
v=spf1 include:_spf.google.com ~all
Then someone added the newsletter tool. Then the help desk. Then the CRM, the invoicing app, and the transactional email service. Each one said "add this include to your SPF record", and each time it worked.
Until one day it didn't, and nothing looked different. Every email from your domain started failing SPF at the same moment. Not one tool: all of them.
The cause is a rule many people never hear about: SPF allows at most 10 DNS lookups.
How the limit works
When a mail server checks SPF, it reads your record and follows it. Some parts of the record make the server do another DNS lookup. The SPF standard (RFC 7208) caps those lookups at 10 per check. Go over, and the result is permerror, a permanent error. Most receivers treat that like a fail.
These parts count toward the 10:
include:amxptrexists:redirect=
These parts don't count:
-
ip4:andip6:(the address is written right there, so no lookup) all
The part people miss: includes are counted all the way down. When you add include:_spf.vendor.com, the receiver opens that record too, and every include, a or mx inside it counts against your 10. A single include can quietly cost three or four lookups.
There is a second, smaller limit: lookups that come back empty (the domain doesn't exist, or has no record) are capped at 2. An include pointing at a vendor you cancelled years ago can trip it.
Count your lookups
dig shows your top-level record:
dig TXT example.com +short | grep spf1
But that doesn't follow the includes, which is where the cost hides. Here's a short Node script that does:
// spf-count.mjs: node spf-count.mjs example.com
import { resolveTxt } from 'node:dns/promises';
async function getSpf(domain) {
const records = (await resolveTxt(domain)).map((r) => r.join(''));
const spf = records.filter((r) => r.toLowerCase().startsWith('v=spf1'));
if (spf.length !== 1) {
throw new Error(`${domain}: found ${spf.length} SPF records (must be exactly 1)`);
}
return spf[0];
}
async function count(domain, depth = 0) {
const spf = await getSpf(domain);
let lookups = 0;
for (const term of spf.split(/\s+/).slice(1)) {
const t = term.replace(/^[+\-~?]/, '').toLowerCase();
const pad = ' '.repeat(depth);
if (t.startsWith('include:') || t.startsWith('redirect=')) {
const target = t.split(/[:=]/)[1];
lookups += 1;
console.log(`${pad}${t}`);
lookups += await count(target, depth + 1);
} else if (/^(a|mx|ptr|exists)([:/]|$)/.test(t)) {
lookups += 1;
console.log(`${pad}${t}`);
}
}
return lookups;
}
const domain = process.argv[2];
const total = await count(domain);
console.log(`\n${domain}: ${total} DNS lookups (limit is 10)`);
Run it on your own domain. The indented tree shows which include is expensive. It's a quick check, not a full validator: it doesn't expand SPF macros, and mx and ptr make extra lookups behind the scenes. That's one more reason to avoid them.
Notice the error for "found 2 SPF records". A domain must have exactly one record starting with v=spf1. Two records is also a permerror, and it's a common mistake when a new tool's setup guide says "add this TXT record" and someone adds a second one instead of editing the first.
Why it matters more now
Since February 2024, Gmail and Yahoo require bulk senders to pass SPF and DKIM and to publish a DMARC record. A broken SPF record no longer just costs you a little reputation. It can push mail to spam or get it rejected.
DMARC passes if either SPF or DKIM passes and lines up with your From domain. So if your DKIM is set up correctly for each sending tool, a broken SPF won't sink every email. Many teams find out their DKIM was never set up for one of those tools only when SPF breaks.
How to get back under 10
1. Remove includes for tools you no longer use. This is the most common fix. Ask whoever handles DNS for the list of tools, and remove every include you can't match to a tool that still sends.
2. Check which domain each tool actually checks SPF against. This one surprises people. SPF isn't checked against the From address your readers see. It's checked against the envelope sender, the Return-Path. Many sending services use their own domain, or a subdomain of yours like mail.example.com, as the Return-Path. If so, their include doesn't belong on your root domain at all, and removing it costs nothing.
Open an email from each tool, view the header, and look at the Return-Path line:
Return-Path: <bounces+123@mail.example.com>
If that domain isn't your root domain, the include on your root is doing nothing for that tool.
3. Move bulk sending to a subdomain. Send newsletters from news.example.com, with its own SPF record. Your root record then only covers the mail your team sends day to day.
4. Replace a and mx with explicit IPs if those servers rarely change. ip4: costs nothing.
5. Be careful with "SPF flattening". Flattening means replacing includes with the IP ranges they currently resolve to. It gets you under the limit, but vendors change their IPs, and a flattened record quietly goes out of date. Only do it with a tool that updates the record automatically.
The 2-minute check
- Run the script on your domain. Over 8? You're one new tool away from breaking.
- Make sure there is exactly one
v=spf1record. - List every include and match each to a tool that still sends.
- Check the Return-Path of each tool's emails.
- Confirm DKIM passes for every tool, so one SPF mistake can't take down all your mail.
We build Cresca, an email platform for marketing email and transactional email. We see broken SPF records in sender setups often enough that we wrote this down.
Top comments (0)