SPF

What Is SPF? Sender Policy Framework Explained

SPF is a DNS TXT record that lists which servers may send mail using your domain in the envelope sender. This guide covers how a receiver evaluates it, every mechanism and qualifier, the lookup limits, the difference between -all and ~all, and why SPF alone does not stop From spoofing.

By MailConfig.pro TeamPublished 6 min read

On this page
  1. What SPF checks
  2. How a receiver evaluates SPF
  3. Mechanisms
  4. Qualifiers and results
  5. -all or ~all?
  6. Limits that break real records
  7. SPF and subdomains
  8. What SPF doesn't do
  9. How to set up SPF
  10. Monitoring SPF over time

SPF (Sender Policy Framework) is a DNS TXT record that lists the servers allowed to send email for a domain. When a message arrives, the receiving server takes the domain from the envelope sender, looks up its SPF record and checks whether the connecting IP address is on the list. The answer is a result such as pass, fail or softfail, which the receiver uses alongside DKIM and DMARC to decide what to do with the message. SPF is defined in RFC 7208.

A typical record looks like this:

TXTexample.com
v=spf1 ip4:192.0.2.10 include:_spf.mailprovider.example -all

It says: the server at 192.0.2.10 may send for example.com, so may every server that _spf.mailprovider.example authorizes, and everything else fails.

What SPF checks

An email has two sender addresses. The one people see is in the From: header. The other is the envelope sender, also called the MAIL FROM, Return-Path or bounce address. Mail servers use it for bounces, and recipients rarely see it.

SPF checks the envelope sender's domain, not the visible From (RFC 7208, section 2.4). It can also check the domain the server gave in its HELO/EHLO greeting, and when the envelope sender is empty, as it is for bounces, the HELO domain is what gets checked.

That is why SPF alone does not stop someone from putting your domain in the From line: they can use their own domain in the envelope, pass SPF for it, and still show your address to the reader. DMARC closes that gap by requiring the SPF domain to align with the From domain.

How a receiver evaluates SPF

  1. Take the envelope sender's domain (or the HELO domain).
  2. Query TXT records at that exact name and keep the ones that start with v=spf1. No record gives the result none. More than one gives permerror (section 4.5).
  3. Read the terms from left to right. The first mechanism that matches the connecting IP decides the result, through its qualifier.
  4. If nothing matches and there is a redirect= modifier, evaluate the record of that domain instead. Otherwise the result is neutral.

Order matters: put the mechanisms that match most of your mail first, and all last. Anything after all is never read.

Mechanisms

Mechanism Matches when DNS lookup?
ip4:192.0.2.0/24 The IP is in this IPv4 range No
ip6:2001:db8::/32 The IP is in this IPv6 range No
a / a:host.example.com The IP is one of the domain's A or AAAA addresses Yes
mx / mx:example.com The IP belongs to one of the domain's mail exchangers Yes
include:_spf.example.net The other domain's SPF record returns pass Yes
exists:%{i}.rbl.example.net The constructed name has an A record Yes
ptr Reverse DNS points back into the domain. RFC 7208 says not to use it Yes
all Always. Used last as the catch-all No

Two modifiers can also appear: redirect=example.net hands evaluation to another domain's record when nothing else matched, and exp= names a TXT record with an explanation for rejected senders. include is the one most people use: email services publish an SPF record and tell customers to include it.

Qualifiers and results

Each mechanism can have a qualifier in front of it. Without one, + is assumed.

Qualifier Result Meaning
+ (default) pass Authorized
- fail Explicitly not authorized
~ softfail Probably not authorized
? neutral No statement either way

The other possible results are none (no SPF record), temperror (a temporary DNS problem) and permerror (the record is broken: bad syntax, two records, or too many lookups).

-all or ~all?

The qualifier on all decides what happens to mail from servers you did not list.

  • -all asks for a hard fail. Some receivers reject such mail during the SMTP conversation, before they look at DKIM or DMARC, so a message that DKIM would have saved can be lost, for example after forwarding.
  • ~all asks for a soft fail. The message is suspicious but not rejected on SPF alone. With a DMARC policy at quarantine or reject, DMARC makes the final call, which is why ~all is common on domains that send mail.
  • ?all and +all provide no protection. +all authorizes every server on the internet and should never be used.

For a domain that never sends email, publish v=spf1 -all.

Limits that break real records

SPF evaluation has hard limits, and exceeding them gives permerror (section 4.6.4):

  • 10 DNS lookups. include, a, mx, ptr, exists and redirect each count, including the ones inside included records. ip4, ip6 and all don't. A company using several email services can hit this without noticing. See fixing "too many DNS lookups" for the causes and fixes.
  • 2 void lookups. Lookups that return no answer, such as an include of a domain that no longer exists, should be limited to two.
  • 10 MX names for each mx mechanism.
  • One record per name. Add new services to the existing record instead of creating a second one.

A TXT string holds at most 255 characters. Longer SPF records are split into several quoted strings, which receivers join without spaces, so put the break between two terms and keep the space at the end of the first part.

SPF and subdomains

SPF has no inheritance. A record at example.com says nothing about mail.example.com. Every name used as an envelope sender or HELO name needs its own record. Many email services use a subdomain of yours for the Return-Path, such as bounce.example.com, and publish or ask you to publish the SPF record there.

Every include you publish also extends trust to someone else's DNS. An include of a vendor's domain that later expires, or a typo in one, can hand your SPF to a stranger. SPF hijacking through dangling records explains how that happens and how to spot it.

What SPF doesn't do

  • It doesn't survive forwarding. A forwarded message arrives from the forwarder's server, which isn't in your record, so SPF fails. DKIM survives forwarding as long as the message isn't modified, which is why you want both.
  • It doesn't protect the visible From address, as explained above. That is DMARC's job.
  • It doesn't say anything about content or whether the sender is trustworthy, only whether the server was authorized by the domain owner.

How to set up SPF

  1. List every service that sends mail with your domain: your mailbox provider, newsletter tool, CRM, helpdesk, billing system and website forms.
  2. Collect the include or IP ranges each one documents.
  3. Build one record, ending in ~all or -all. The SPF record generator assembles it from your include domains.
  4. Publish it as a TXT record at the domain itself (the host field is usually @).
  5. Check it for syntax errors and the lookup count.
  6. Publish a DMARC record with a reporting address, and watch the reports to find senders you missed.

Monitoring SPF over time

SPF records drift: services change their IP ranges, someone adds a new tool, an include gets nested deeper. DMARC aggregate reports show every server that sent mail as your domain and whether SPF passed and aligned. MailConfig.pro's DMARC monitoring turns those reports into a list of sending sources, so a new sender or a failing one stands out instead of hiding in XML.

Frequently asked questions

Can a domain have two SPF records?

No. If a receiver finds more than one TXT record starting with v=spf1 at the same name, the result is a PermError. Merge everything into one record.

Should I use -all or ~all?

Both tell receivers that unlisted servers are not authorized. -all asks for a hard fail and ~all for a soft fail. Once DMARC is at quarantine or reject, ~all is a common choice for sending domains because DMARC decides the outcome. Domains that never send mail should use -all.

Does SPF protect the From address people see?

Not on its own. SPF checks the envelope sender (the Return-Path), which recipients don't see. DMARC connects SPF to the visible From domain through alignment.

Do subdomains inherit the SPF record of the parent domain?

No. SPF has no inheritance. Every hostname used as an envelope sender or HELO name needs its own SPF record.

References

spfemail authenticationtxt recordenvelope fromalignment

DMARC

What Is DMARC? How Email Authentication Fits Together

DMARC is a DNS record that ties SPF and DKIM to the domain in the visible From address, states what receivers should do with mail that fails, and requests reports. This guide covers alignment, the record syntax, policies, reporting and what happens when a domain has no record.

· 10 min read

DKIM

What Is DKIM? DomainKeys Identified Mail Explained

DKIM adds a cryptographic signature to every message, and receivers verify it with a public key in your DNS. This guide covers the DKIM-Signature header, selectors and key records, key sizes and Ed25519, key rotation, forwarding and mailing lists, and how DKIM alignment makes DMARC work.

· 6 min read

SPF

SPF PermError: "Too Many DNS Lookups" and Other Causes

SPF returns permerror when a receiver cannot interpret your record. The usual cause is more than 10 DNS-querying terms, but extra void lookups, two SPF records, a syntax error or an include with no SPF record do the same. This guide shows how lookups are counted and gives corrected records.

· 8 min read

DNS security

SPF Hijacking: How Dangling CNAMEs and Typos Let Spoofing Pass DMARC

Some spoofed mail passes DMARC because attackers took over a name your DNS still trusts: a CNAME to an expired domain, a mistyped include, or a CIDR typo. How the takeover works, how to spot it in DNS and in DMARC aggregate reports, and how to close it.

· 8 min read