Sender Policy Framework (SPF) is an email authentication protocol that allows domain owners to specify which mail servers are authorized to send emails on behalf of their domain. By publishing SPF records in DNS, organizations can prevent email spoofing and improve their email deliverability by helping receiving servers verify the legitimacy of incoming messages.
How SPF Works
Authentication Process
When an email is received, the receiving mail server performs the following steps:
- Extract the sender domain: Identifies the domain from the email’s “envelope from” address
- Query DNS records: Looks up the SPF record for that domain
- Validate the sender: Compares the sending server’s IP address against the authorized list
- Assign a result: Returns pass, fail, softfail, neutral, or other status codes
If the sending server’s IP address matches one of the authorized servers in the SPF record, the email passes SPF authentication. Failed authentication may result in the email being marked as spam or rejected entirely.
SPF Record Syntax
Basic Structure
An SPF record is a TXT record published in DNS that begins with “v=spf1” followed by mechanisms and modifiers:
v=spf1 ip4:192.0.2.0/24 include:_spf.example.com -all
Common Mechanisms
- ip4/ip6: Specifies authorized IP addresses or ranges
- a: Authorizes the domain’s A record
- mx: Authorizes the domain’s MX records
- include: References another domain’s SPF record
- all: Catch-all mechanism, typically with “-all” (fail) or “~all” (softfail)
Setting Up SPF Records
Step-by-Step Implementation
- Identify authorized senders: List all mail servers that send on your behalf (including third-party services)
- Create the SPF record: Build the record using appropriate mechanisms
- Publish to DNS: Add the TXT record to your domain’s DNS
- Test the record: Use SPF validation tools to verify correct syntax
- Monitor results: Track authentication results and adjust as needed
Example SPF Records
Simple setup:
v=spf1 mx -all
Complex setup with multiple services:
v=spf1 ip4:192.0.2.0/24 include:_spf.google.com include:spf.protection.outlook.com -all
SPF Limitations
The 10 DNS Lookup Limit
SPF has a critical limitation: records cannot exceed 10 DNS lookups. This includes:
- Each “include” mechanism counts as one lookup
- The included domain’s lookups also count toward the limit
- Exceeding 10 lookups causes SPF to return “permerror”
To manage this limitation:
- Minimize the use of “include” statements
- Use IP addresses instead of “include” where possible
- Consider SPF flattening services (with caution)
- Consolidate email sending services
Other Limitations
- No subdomain inheritance: Each subdomain needs its own SPF record
- Single record requirement: Only one SPF record per domain
- 255-character limit: DNS TXT record length restrictions
Troubleshooting SPF Issues
Common Problems
Too many DNS lookups: Reduce “include” statements or consolidate services Syntax errors: Validate record structure using SPF checkers Missing mechanisms: Ensure all sending sources are authorized Wrong qualifier: Verify “-all” vs “~all” usage matches your needs
Testing Tools
Use these resources to validate your SPF records:
- MXToolbox SPF Record Lookup
- Google Admin Toolbox
- DMARC Analyzer SPF Checker
- Command line:
dig txt example.com
SPF with DKIM and DMARC
Comprehensive Email Authentication
While SPF is important, it works best as part of a complete authentication strategy:
SPF: Validates the sending server DKIM: Verifies email content hasn’t been modified DMARC: Provides reporting and policy enforcement based on SPF and DKIM
Best Practices
- Implement all three protocols (SPF, DKIM, and DMARC)
- Start with a lenient DMARC policy and gradually tighten
- Monitor DMARC reports to identify unauthorized senders
- Maintain up-to-date SPF records as your infrastructure changes
- Consider BIMI implementation once authentication is solid
SPF is a foundational element of email authentication that protects your domain from spoofing while improving deliverability. When properly configured alongside DKIM and DMARC, it creates a robust defense against email-based threats and establishes trust with receiving mail servers.