Leadmetrics
Free tool, no sign-up

SPF record generator

Build an SPF record from your sending providers, with the ten-lookup limit counted as you go.

Pick from: google, microsoft, sendgrid, mailchimp, mailgun, postmark, ses, zoho, hubspot, klaviyo — or type an include: mechanism directly.

Your own mail server or application server, e.g. 203.0.113.4 or 203.0.113.0/24.

Only if your inbound mail servers also send. Each MX host costs a DNS lookup.

SPF record

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

Before you ship this

  • Note: About 4 of 10 DNS lookups used. The counts include each provider's own nested includes, so verify with a live checker before relying on the headroom.
  • Warning: A domain may publish exactly one SPF record. If you already have one, merge these mechanisms into it rather than adding a second — two records is a permerror.
  • Note: SPF breaks when mail is forwarded, because the forwarder is not on your list. DKIM survives forwarding, and DMARC is what ties the two to your domain. Publish all three.

How to use it

  1. List everyone who sends mail as your domain — your mailbox provider, your marketing platform, your CRM, your invoicing tool.
  2. Add any IP addresses of your own that send mail, such as an application server.
  3. Watch the lookup count. Each include costs one DNS lookup plus whatever it nests, and over ten the record stops working entirely.
  4. Publish it as a single TXT record at the root of your domain, then check it with a lookup tool before trusting it.

The lookup limit is the whole difficulty

SPF syntax is simple enough to write by hand. What catches people is that every include triggers a DNS query, that query can return a record with its own includes, and all of them count toward a hard limit of ten.

Google Workspace costs around four by itself. Add Microsoft 365, a marketing platform and a CRM and you are at the ceiling without having done anything unusual. Crossing it produces a permerror, and a permerror means receivers behave as though you published nothing.

The lookup counts here are approximate by nature — a provider can change its own nesting without telling anyone — so treat a count near the limit as a warning rather than a precise measurement, and verify with a live checker before relying on it.

What to do when you run out

Two real options. Move bulk senders to a subdomain with its own SPF record — newsletters from mail.yourdomain.com get their own ten lookups and their own reputation. Or use an SPF flattening service, which resolves the includes to IP ranges and keeps them updated; that trades the limit for a dependency on someone keeping the list current.

SPF alone does very little

SPF checks the envelope sender, which is not the address the recipient sees, and it breaks on forwarding. On its own it barely affects whether your mail arrives.

What it does is give DMARC something to check. DMARC passes when SPF or DKIM passes and the domain aligns with the visible From address — that alignment is what actually protects your domain, and SPF is one of its two legs. Publish all three, in the order SPF, DKIM, DMARC.

Never publish +all

+all authorises every host on the internet to send as your domain. It is worse than having no record, because it looks deliberate, and it will be found and used. It exists in the specification; it has no legitimate use.

SPF record generator FAQ

What is the SPF ten lookup limit?

SPF allows a maximum of ten DNS-querying mechanisms per evaluation. Each include, a, mx and exists counts, and includes that nest their own includes count too — Google Workspace alone is about four. Exceed ten and the record is a permerror, which most receivers treat as having no SPF at all. It is the single most common way a working SPF record quietly stops working.

Should I use ~all or -all?

Start with ~all, which is a softfail: receivers note the failure but usually still deliver. Once your DMARC reports have been clean for a few weeks and you are confident every sender is listed, move to -all. Going straight to -all means a forgotten sender disappears silently, and the sender you forgot is usually the invoicing system.

Can I have two SPF records?

No. A domain may publish exactly one, and two is a permerror — the same outcome as having none. If you already have a record, merge the new mechanisms into it rather than adding a second TXT record.

Why does SPF fail when my email is forwarded?

Because forwarding changes the sending server, and the forwarder is not on your list. This is inherent to SPF and not something you can configure around. It is why DKIM matters: a DKIM signature survives forwarding, so DMARC can still pass on the DKIM side when SPF breaks.

How do I get back under ten lookups?

Remove senders you no longer use, which is usually the first two or three. After that, move a platform onto its own subdomain and give that subdomain its own SPF record, so its includes no longer count against the root. Both are better than flattening.

Is SPF flattening safe?

Only if it is automated. Replacing includes with the IP addresses behind them fixes the lookup count today and breaks silently the day your provider changes infrastructure, which they do without telling you. If you flatten, use a service that re-checks and republishes; never do it by hand.

Which address does SPF actually check?

The envelope sender — the return path — not the From address a recipient sees. That is why SPF alone cannot stop spoofing: a message can pass SPF for one domain while displaying another in the From line. Alignment, which DMARC enforces, is what closes that gap.

Do subdomains inherit the SPF record?

No. Each subdomain that sends mail needs its own record, and a subdomain with none is treated as having no policy at all. This is also the mechanism that makes subdomain delegation a useful answer to the lookup limit.

Is there a length limit on the record?

A single DNS string is capped at 255 characters, and while longer records can be split across strings, the total response should stay small enough to avoid DNS problems. A record pushing those limits is almost always one that needs pruning rather than splitting.

What should a domain that sends no mail publish?

An SPF record authorising nothing, with a hard fail, alongside a DMARC record at reject. Parked and brand-protection domains are attractive to spoofers precisely because nobody maintains them, and two DNS records close that off permanently.