Draft — in editorial review, not yet published. Content has not been approved by a human reviewer.
Lesson 42 / 50 · Version 2.2.0
SPF: Setup, Limits and Diagnosis
- Level
- Beginner–Intermediate
- Duration
- 15 min learn + 15 min apply
- Prerequisites:
- Lesson 41
Why it matters: SPF is the first line of sender authentication, and the most common place small businesses break their own email by adding a second record or too many includes.
By the end you can:
- Explain what SPF checks
- Read and write a basic SPF record
- Diagnose duplicates and the 10-lookup limit
- Explain why SPF alone doesn't protect the visible From
Learn (15 min)
1. What SPF evaluates (5 min)
Sender Policy Framework lets a domain publish which servers may send mail using that domain in the SMTP envelope sender (MAIL FROM / return-path). Receivers compare the connecting server to the policy. The envelope sender is not necessarily the From address people see.
2. Reading a policy (5 min)
example.org. TXT "v=spf1 include:spf.protection.outlook.com include:_spf.newsletter-vendor.example ip4:203.0.113.25 -all"
| Part | Meaning |
|---|---|
v=spf1 | SPF version marker |
include:domain | Also allow that domain's published policy |
ip4: / ip6: | Allow a specific address/range |
a / mx | Allow the domain's A or MX hosts |
-all | Hard fail everything else |
~all | Soft fail |
?all | Neutral |
| Include every real sender (staff mail, newsletter tool, CRM, billing) or legitimate mail will fail. |
3. Limits and diagnosis (5 min)
- Publish one SPF record per name. Two
v=spf1records can cause a permanent error. - SPF evaluation allows at most 10 DNS-query-causing terms (
include,a,mx,ptr,exists,redirect). Nested includes count. Exceeding it breaks SPF. - Forwarding often fails SPF because the forwarder's IP isn't in the original domain's policy.
Diagnosis sequence: inventory senders →
dig +short TXT <domain>→ look for duplicates/typos → count lookups → send a test message and readAuthentication-Results.
Apply (15 min)
Worked example (3 min). example.org sends through its staff mail provider and a newsletter tool. Someone added a second SPF record for the newsletter tool. Fix: merge into one record containing both includes; keep ~all while verifying and move to -all only after confirming all senders; recount lookups; test messages from each system.
Lab (7 min): SPF inventory and merge.
- List every system that sends email as your domain (ask finance, marketing, support, apps).
- For each, note the vendor's documented SPF include or IPs.
- Write one merged SPF record.
- Count lookup-causing terms (include each vendor's nested ones if you can check them).
Deliverable: A sender inventory and a proposed SPF record. You're done when: There's exactly one record and the lookup count is ≤10.
Check yourself (5 min)
- Which identity does SPF primarily evaluate?
- Does SPF alone prove the visible From is authorized?
- How many SPF records per name?
- Scenario: SPF returns "permerror" after a vendor was added. What two causes do you check?
- Why can forwarding break SPF?
Reference
Common mistakes
| Symptom | Likely cause | Fix |
|---|---|---|
| SPF permerror | Duplicate records or >10 lookups | Merge; trim includes |
| Legit mail failing | Missing sender | Inventory senders; add include |
| Over-trusting SPF | Ignores From alignment | Add DKIM + DMARC |
Cheat sheet: Inventory senders → inspect authoritative TXT → single policy → lookup count → verify with real test messages.
Key terms: SPF, envelope sender, include, qualifier, permerror, lookup limit.
Interview prompts: How do you safely tighten from ~all to -all?
Go deeper: SPF, RFC 7208 · Microsoft: Set up SPF
Next: Lesson 43 — DKIM.