An SPF (Sender Policy Framework) record is a DNS TXT record that lists which mail servers are authorized to send email on behalf of your domain, and it protects your domain by helping receiving mail servers reject or flag forged messages that pretend to come from you. By publishing this list, you give mail providers a way to check whether an incoming email claiming to be from your domain actually originated from a server you approved. This reduces the risk of your domain being used in email spoofing, phishing, and spam campaigns that can damage your reputation and harm your recipients.
Background: Why SPF Exists
Email was designed in an era when almost no one worried about authentication. The original Simple Mail Transfer Protocol (SMTP) does not verify that the sender address in an email is legitimate. Anyone can craft an email with a "From" header that says they are your bank, your boss, or your own domain. This weakness is what makes email spoofing possible.
SPF was introduced in the early 2000s as one of the first practical attempts to close that gap. It was formalized in RFC 4408 in 2006 and later updated in RFC 7208 in 2014. The idea is simple: you publish a record in your domain's DNS that says which IP addresses or hostnames are allowed to send mail for your domain. When a receiving server gets a message, it can look up your SPF record and check if the sending server is on the list. If not, the message is more likely to be spam or a forgery.
SPF is not a complete email security solution. It works best when combined with DKIM (DomainKeys Identified Mail) and DMARC (Domain-based Message Authentication, Reporting, and Conformance). But SPF remains a foundational layer that every domain owner should implement.
How an SPF Record Works
To understand SPF, you need to know what happens when you send an email. Your mail server connects to the recipient's mail server and delivers the message. The recipient's server sees the envelope sender (the return-path address) and the domain in the From header. SPF checks the envelope sender, not the From header, because the envelope is what SMTP uses for delivery.
Here is the step-by-step process:
- Your mail server sends a message to the recipient's server.
- The recipient's server extracts the domain from the envelope sender (e.g., example.com).
- It performs a DNS lookup for the SPF record at example.com. This is a TXT record that starts with
v=spf1. - The SPF record contains a series of mechanisms and qualifiers that define which IP addresses are allowed to send.
- The recipient's server checks the IP address of the connecting server against those rules.
- If the IP matches an allowed entry, the check passes. If not, the result is a fail (or a softer result like softfail, depending on the qualifier).
- The recipient's server then decides what to do: accept, reject, or mark as spam. That decision is influenced by SPF, but also by DKIM and DMARC.
For example, an SPF record like v=spf1 ip4:192.0.2.1 include:_spf.google.com -all says: allow mail from IP 192.0.2.1, allow mail from Google's servers (as listed in _spf.google.com), and reject all others (the -all at the end).
SPF Record Syntax and Mechanisms
An SPF record is a single string of text. It always starts with v=spf1 to identify the version. After that, you list mechanisms. Each mechanism can have a qualifier that determines the result if it matches:
+(pass) – the default if no qualifier is written-(fail) – the domain explicitly says this server is not authorized~(softfail) – the domain says this server is probably not authorized, but the message should be accepted with suspicion?(neutral) – no opinion
Common mechanisms include:
ip4:– allows a specific IPv4 address or range (e.g.,ip4:203.0.113.5orip4:203.0.113.0/24)ip6:– allows a specific IPv6 address or rangeinclude:– pulls in the SPF record of another domain (e.g.,include:spf.protection.outlook.comfor Microsoft 365)a– allows the domain's A record IP(s)mx– allows the domain's MX serversexists:– checks if a domain resolves (used for special cases)all– matches every IP; usually used at the end with a qualifier like-allor~all
You can also use the redirect= modifier to point to another domain's SPF record. The exp= modifier lets you specify an explanation for failures, but it is rarely used.
How to Create and Publish an SPF Record
Before you create an SPF record, you need to know which services send email on behalf of your domain. Common ones include your own mail server, a web hosting provider, an email marketing service like Mailchimp or SendGrid, or a SaaS platform that sends transactional emails.
Here is a practical process:
- List every service that sends email from your domain. Check your email headers if you are unsure.
- Find the IP addresses or hostnames for each service. Many providers publish their SPF include values (e.g.,
include:sendgrid.net). - Write your SPF record. Start with
v=spf1, then add mechanisms for each service. - End with
-allif you are confident you have listed everything, or~allif you want a softer policy. - Publish the record as a TXT record in your DNS. The host/name is usually
@(your domain root). - Wait for DNS propagation (can take a few minutes to 48 hours).
- Test your record using an online SPF checker or by sending a test email and examining the headers.
Important: You can only have one SPF record per domain. If you add a second one, it will cause a permanent error (a "permerror") and SPF checks will fail. If you need to add more services, edit the existing record.
Common Problems and Misconceptions
One common mistake is using too many DNS lookups. SPF allows a maximum of 10 DNS lookups per check. Each include:, a, mx, or exists: mechanism counts as a lookup. If you exceed 10, the SPF check returns a permanent error, and your emails may be rejected. To avoid this, consolidate includes or use IP addresses directly when possible.
Another misconception is that SPF protects against all spoofing. It does not. SPF only checks the envelope sender, not the visible From header. An attacker can still spoof the From header to show your domain while using a different envelope sender. That is why DMARC is necessary – it aligns the From header with the authenticated domain and tells receivers what to do if SPF or DKIM fails.
Also, SPF does not encrypt email or protect the content. It only helps with sender authentication.
Finally, some people think that ~all (softfail) is as good as -all (hard fail). Softfail is a safer starting point because it tells receivers to accept the message but mark it suspicious. Hard fail is stricter and may cause legitimate emails to be rejected if you have not listed all your sending servers. Start with ~all and move to -all once you are sure everything is covered.
SPF vs. DKIM vs. DMARC
SPF is often mentioned alongside DKIM and DMARC. They work together:
- SPF verifies that the sending server is authorized by the domain owner, based on the envelope sender.
- DKIM adds a digital signature to the email headers. The signature is validated using a public key published in DNS. This proves the email was not tampered with and that it came from a domain that owns the key.
- DMARC tells receivers what to do if both SPF and DKIM fail. It also requires alignment between the From domain and the domains used in SPF/DKIM. DMARC gives you reporting so you can see who is sending email using your domain.
SPF alone is not enough. For example, an attacker can set up their own server and send email with your domain in the From header but with a different envelope sender. SPF may pass for the envelope sender, but DMARC alignment would fail. DMARC is the policy layer that closes that gap.
Costs and Safety Considerations
Publishing an SPF record costs nothing – it is just a DNS record. The time and effort come from identifying all your legitimate sending sources and maintaining the record as you add or remove services.
Safety-wise, the biggest risk is making your SPF record too strict before you have listed all your senders. If you use -all and miss a legitimate server, your emails will be rejected by receivers. That can hurt your deliverability and even your business. To avoid this, start with ~all and monitor your email logs for a few weeks. Use DMARC reporting to see which sources are failing and adjust accordingly.
Also, be careful when using include: from third-party providers. If that provider changes their SPF record, it can affect yours. Always test after any changes.
Frequently Asked Questions
Do I need an SPF record if I use a third-party email service like Gmail or Outlook?
Yes. Even if you use a hosted email service, you should publish an SPF record that includes that service's SPF include. For example, Google Workspace requires you to add include:_spf.google.com to your SPF record. This tells other mail servers that Google is allowed to send mail for your domain.
What happens if I don't have an SPF record?
Without an SPF record, receiving servers have no way to verify if an email from your domain is legitimate. They may still accept it, but your domain is more vulnerable to spoofing. Many mail providers will treat emails from domains without SPF and DMARC as suspicious, which can hurt your deliverability.
Can I have more than one SPF record?
No. You should only have one SPF record per domain. If you publish multiple TXT records that start with v=spf1, it causes a permanent error and SPF checks will fail. If you need to add more senders, edit the existing record.
What does the -all at the end of an SPF record do?
The -all is a hard fail qualifier. It tells receiving servers that any server not listed in the record is not authorized to send mail for your domain. This is the strictest setting. A softer alternative is ~all (softfail), which marks unauthorized mail as suspicious but does not reject it outright.
How do I test my SPF record?
You can use online SPF checkers that analyze your DNS record and tell you if it is valid. You can also send a test email to a service like Gmail and look at the message headers. The headers will show an SPF result (pass, fail, softfail, etc.).
Does SPF protect my domain from all email spoofing?
No. SPF only checks the envelope sender, not the From header that users see. An attacker can still spoof the From header. To fully protect your domain, you need to combine SPF with DKIM and DMARC. DMARC ensures that the From domain matches the authenticated domains, and it gives you a policy to reject unauthenticated mail.