SPF (Sender Policy Framework) is an email authentication method that specifies which mail servers are authorized to send email on behalf of a domain via a DNS record. By publishing a list of approved sending IP addresses and third-party services, domain owners help receiving mail servers detect and block sender address forgery, commonly known as spoofing. Alongside DKIM and DMARC, SPF serves as a foundational layer for email deliverability and domain reputation.
How it works
To implement SPF, a domain administrator publishes a specially formatted TXT record in the domain's DNS zone. When an incoming message arrives, the receiving mail server inspects the domain in the SMTP MAIL FROM (Return-Path) address and queries DNS for its SPF policy. The server then compares the connecting client's IP address against the authorized sources listed in the record.
An SPF record consists of a version prefix followed by mechanisms and qualifiers:
v=spf1: Identifies the TXT record as an SPF policy.ip4andip6: Explicitly authorize specific IPv4 or IPv6 addresses and CIDR ranges.include: Authorizes another domain's SPF policy, commonly used for cloud email providers or marketing platforms.-all(HardFail) or~all(SoftFail): Qualifiers placed at the end of the record to instruct receivers on how to treat unmatched IPs, signaling either outright rejection or suspicious marking.
Example
A domain using Microsoft 365 for corporate email and a dedicated application server with a static IPv4 address would publish a single DNS TXT record at the root domain (@):
v=spf1 ip4:203.0.113.25 include:spf.protection.outlook.com -all
You can verify that the record is live and properly propagated using the dig command in a terminal:
dig +short TXT example.com
What matters when choosing a server or hosting
When selecting a VPS, dedicated server, or managed hosting provider for workloads that send transactional email, network and DNS stability are critical. Your host should provide static, dedicated IPv4 and IPv6 addresses so your ip4 and ip6 mechanisms remain valid without frequent DNS edits. Clean IP reputation also matters: shared hosting environments often place multiple tenants on the same outbound mail IP, meaning another user's spam activity can hurt your deliverability even with a valid SPF record.
Additionally, look for hosting platforms or DNS providers that offer fast propagation, API-driven DNS management, and support for outbound SMTP relay services if your host blocks standard mail ports by default.
Common mistakes
- Publishing multiple SPF records: A domain must have only one
v=spf1TXT record. Having two or more causes receiving servers to return aPermError, invalidating SPF completely. - Exceeding the 10-DNS-lookup limit: Mechanisms such as
include,a,mx, andredirecttrigger DNS queries. If resolving a record requires more than 10 lookups, authentication fails with aPermError. - Using
+all: The+allqualifier authorizes every server on the internet to send email as your domain, defeating the purpose of SPF. - Forgetting third-party senders: Failing to add
includestatements for CRM tools, ticketing systems, or web forms causes legitimate automated emails to land in spam.
FAQ
Does SPF protect the "From" address visible to users?
Not directly. SPF validates the technical Return-Path address used during SMTP transport rather than the header From address displayed in email clients. To align and protect the visible sender address, you must pair SPF with DMARC.
What is the difference between -all and ~all?
The -all (HardFail) qualifier tells receiving servers that unauthorized senders should be rejected, while ~all (SoftFail) indicates that unauthorized mail should be accepted but flagged as suspicious. Most administrators use ~all during initial testing and switch to -all once all legitimate mail sources are verified.
How can I fix an SPF record that exceeds 10 DNS lookups?
You can reduce lookups by removing unused include entries, replacing hostname-based mechanisms with direct ip4 or ip6 ranges where possible, or delegating transactional and marketing emails to dedicated subdomains with their own separate SPF records.