SPF stands for Sender Policy Framework, an email authentication standard that helps prevent spoofing and phishing. In plain terms, it lets a domain owner publish a list of mail servers that are allowed to send email on their behalf. When you set up SPF, you create a DNS TXT record that receiving mail servers can check to verify that an incoming message really came from an authorized server. This article explains what SPF is, how it works, and how to set it up correctly.
What Is SPF and Why Does It Matter?
SPF is an open standard defined in RFC 7208. It was introduced in the early 2000s as a response to the growing problem of email spoofing, where attackers forge the "From" address to make messages look like they come from a trusted domain. SPF works by letting a domain owner declare which IP addresses are allowed to send mail for that domain. When a receiving server gets a message, it can look up the SPF record for the domain in the "From" address and check if the sending server's IP is listed. If it is not, the message may be rejected or marked as spam.
SPF is not a complete email security solution. It only verifies the envelope sender (the return-path address), not the visible "From" header. That is why SPF is usually combined with DKIM (DomainKeys Identified Mail) and DMARC (Domain-based Message Authentication, Reporting, and Conformance). Together, these three standards form the backbone of email authentication.
How SPF Works: A Step-by-Step Look
Here is the process that happens when a receiving mail server checks SPF:
- The sender's mail server sends a message with a return-path (envelope sender) that contains the sending domain.
- The receiving server looks up the DNS TXT record for that domain to find the SPF record (a string starting with
v=spf1). - The receiving server parses the record to see which IP addresses or hostnames are allowed to send.
- It compares the IP address of the server that actually sent the message against the list.
- If the IP matches an allowed entry, SPF passes. If not, SPF fails or returns a neutral result.
SPF results can be pass, fail, softfail, neutral, none, temperror, or permerror. The receiving server decides what to do with those results based on its own policy. For example, a strict server might reject a message on a hard fail, while a softer policy might just flag it.
SPF Record Syntax: What Goes Into the TXT Record
An SPF record is a single DNS TXT record that starts with v=spf1. After that, you add mechanisms and qualifiers. The most common mechanisms are:
ip4:– allows a specific IPv4 address or range, e.g.,ip4:192.0.2.1orip4:192.0.2.0/24ip6:– allows a specific IPv6 address or rangeinclude:– includes the SPF record of another domain, e.g.,include:spf.example.coma– allows the domain's A record IP(s)mx– allows the domain's MX server IP(s)exists:– checks if a domain resolves (used for special cases)all– matches every IP; usually placed at the end with a qualifier like-all(hard fail) or~all(softfail)
Qualifiers are prefixes that tell the receiver how to treat a match: + for pass (default), - for fail, ~ for softfail, and ? for neutral. A typical SPF record looks like this:
v=spf1 ip4:192.0.2.1 include:spf.mailprovider.com -all
That record says: allow the IP 192.0.2.1 and whatever the mail provider's SPF record allows, and fail everything else.
How to Set Up SPF: Step-by-Step Guide
Setting up SPF involves creating a DNS TXT record for your domain. Here are the general steps:
- Identify all mail senders for your domain. This includes your own mail server, any third-party email service (like a marketing platform or helpdesk), and any service that sends on your behalf (e.g., a CRM or newsletter tool).
- Get the IP addresses or include domains for each sender. Your email service provider usually gives you a specific SPF snippet to include, such as
include:spf.yourprovider.com. - Construct your SPF record. Start with
v=spf1, then add each mechanism. End with-allif you want to be strict, or~allif you want a softer policy. Avoid using multipleallmechanisms, and never putallbefore your allowed mechanisms. - Publish the record in DNS. Log in to your domain registrar or DNS hosting provider, go to the DNS management page, and add a new TXT record. The host/name is usually
@(or your domain name), and the value is the full SPF string. - Test your SPF record. Use an online SPF checker or send a test email to a mailbox that shows authentication results (like Gmail's "Show original"). Verify that SPF passes.
Remember that SPF records have a limit of 255 characters and a maximum of 10 DNS lookups (including those caused by include: and other mechanisms). If you exceed that, your record will fail to validate.
Common SPF Problems and How to Avoid Them
Many SPF issues come from misconfiguration. Here are the most frequent ones:
- Too many DNS lookups: Each
include:,a,mx, orexistscan add to the lookup count. If you hit more than 10, SPF returns apermerror. To fix this, consolidate your senders or use a subdomain for some services. - Multiple SPF records: You can only have one SPF record per domain. If you add a second one, both are ignored. Make sure you edit the existing record instead of adding a new one.
- Missing
-allor~all: Without anallmechanism, the record is incomplete and may be treated as neutral. Always end with-allor~all. - Using
ptrmechanism: Theptrmechanism is deprecated and causes extra lookups. Avoid it. - Including too many third-party services: Each service adds an
include:which can quickly exceed the lookup limit. If you have many senders, consider using a subdomain for some services (e.g.,mail.yourdomain.com) and set up a separate SPF record there.
SPF vs. DKIM vs. DMARC: How They Compare
SPF is just one piece of the email authentication puzzle. Here is how it differs from the other two:
- SPF checks the envelope sender (return-path) against a list of allowed IPs. It does not protect the visible "From" header.
- DKIM uses a digital signature to verify that the message was not tampered with and that it genuinely comes from the domain. The signature is stored in the email headers and verified using a public key in DNS.
- DMARC builds on SPF and DKIM. It tells receiving servers what to do if both checks fail (e.g., quarantine or reject) and provides reporting so domain owners can see who is sending email using their domain.
For robust protection, you should set up all three. SPF alone is not enough because attackers can still spoof the visible "From" address even if SPF passes on the envelope sender.
Frequently Asked Questions
What does SPF stand for?
SPF stands for Sender Policy Framework. It is an email authentication standard that lets a domain owner publish which mail servers are allowed to send email for that domain.
Can I have multiple SPF records?
No. You can only have one SPF record per domain. If you add more than one, receiving servers may ignore all of them, which effectively disables SPF for your domain.
What does -all mean in an SPF record?
-all is a hard fail qualifier. It tells receiving servers that any server not listed in the SPF record is not authorized to send email for your domain, and the message should be rejected or flagged as spam.
How do I check my SPF record?
You can use an online SPF checker tool or run a DNS lookup for the TXT record of your domain. For example, using a command line tool like dig on Linux or macOS: dig TXT yourdomain.com. Look for a record that starts with v=spf1.
What happens if my SPF record is too long?
If your SPF record exceeds 255 characters or causes more than 10 DNS lookups, it will fail validation. Receiving servers may return a permerror and treat the message as if SPF is not set up. To fix this, remove unnecessary mechanisms or use a subdomain for some senders.
Do I need SPF if I use a third-party email service?
Yes. Even if you use Gmail, Outlook, or a marketing platform, you still need to add an SPF record that includes their sending servers. Most providers give you a snippet to include in your SPF record.
Final Thoughts on SPF Setup
Setting up SPF is a straightforward but critical step in email security. It helps protect your domain from being used in phishing scams and improves your email deliverability. Remember to keep your record under the DNS lookup limit, avoid multiple SPF records, and combine SPF with DKIM and DMARC for full protection. If you are unsure about any part of the setup, consult your email service provider's documentation or a qualified IT professional.