Sub topic 4
SPF: authorizing the servers that send for you
This chapter assumes you can read and edit DNS TXT records, know the basics of SMTP, and can read raw email headers. It covers SPF only. Alignment and DMARC come in later chapters.
What SPF does
Sender Policy Framework (SPF) lets a domain publish a list of servers allowed to send mail for it. The receiving server takes the connecting IP address, looks up the SPF record for the domain, and checks whether that IP is on the list.
SPF does not check the visible From address. It checks the domain used in the SMTP envelope, called the Return-Path or MAIL FROM, or the HELO name when the envelope sender is empty. Many marketing platforms set the envelope domain to a bounce domain they control. The bounce domain can therefore differ from your From domain. That gap is why alignment matters.
Anatomy of a record
An SPF record is a TXT record that starts with v=spf1. The rest is a list of mechanisms read left to right. The first match decides the result.
example.com. TXT "v=spf1 include:_spf.esp.example.net -all"| Part | Meaning |
|---|---|
| `include:` | Also accept whatever the named domain's SPF record authorizes |
| `ip4:` / `ip6:` | Accept a specific address or range |
| `a` / `mx` | Accept the addresses of the domain's A or MX records |
| `-all` | Fail anything that did not match |
| `~all` | Softfail anything that did not match |
An include is how you authorize an email service provider (ESP). The ESP maintains the IP list, so you do not need to update your record when its servers change.
Publishing and checking
Publish one SPF record per domain. Use the exact include: value your ESP documents. Then confirm it from the command line.
dig +short TXT example.comThe output should contain exactly one string beginning with v=spf1. In a received message, look for the result in the Authentication-Results header, such as spf=pass smtp.mailfrom=bounce.example.com.
Common errors
- Two SPF records on one domain. Receivers return
permerror, and SPF fails. Merge them into one record. - More than 10 DNS lookups.
include,a,mx,ptr,exists, andredirecteach count toward a limit of 10. Exceeding it also givespermerror. Remove unused includes. Replace stable vendor includes withip4:entries only if you can keep them current. - Ending with
+allor?all. These permit or ignore every sender and defeat the purpose. - Forgetting a sender. A CRM, a support desk, or a billing system that sends as your domain needs authorization too.
- Editing the wrong domain. If your ESP uses a custom bounce domain, SPF is evaluated on that domain, not on your From domain.
Why it matters for bulk senders
Gmail, Yahoo, and Microsoft require bulk senders to authenticate with SPF and DKIM and to publish DMARC. A passing SPF result on its own does not satisfy DMARC. The SPF domain must also align with the From domain, or DKIM must align instead. A message can show spf=pass and still not benefit from it in DMARC, which the later alignment chapter explains with examples.
Start with ~all while you inventory your senders, then move to -all once the record covers every legitimate source.
Exercise
Your DNS has two TXT records on example.com, one starting "v=spf1 include:spf.esp.example.net -all" and another starting "v=spf1 include:spf.crm.example.org -all". Mail from both services shows spf=permerror. What is wrong, and how do you fix it?
Show answer
A domain may publish only one SPF record, so receivers return permerror when they find two. Merge them into one record, for example "v=spf1 include:spf.esp.example.net include:spf.crm.example.org -all", delete the second record, and keep the total DNS lookups at 10 or fewer.