SPF (Sender Policy Framework) records tell receiving mail servers which IP addresses are allowed to send email for your domain. Setting them up correctly prevents your emails from being marked as spam or rejected, and it stops spammers from forging your domain. This guide walks you through the exact steps to create, publish, and test an SPF record.
What You'll Need
- Access to your domain's DNS management panel (usually at your domain registrar or hosting provider)
- A list of all services that send email on behalf of your domain (e.g., your web server, email marketing platform, CRM, or third-party email relay)
- The IP addresses or hostnames of those services (most providers list this in their help docs)
- Basic understanding of DNS record types (TXT records, and optionally MX records)
Step-by-Step
- List all email senders for your domain. Write down every service that sends email with your domain in the From or Envelope-From address. Common ones: your website's contact form (if it sends from your domain), your email hosting provider, a newsletter service like Mailchimp or SendGrid, and any transactional email service (e.g., Amazon SES, Postmark). Do not forget automated notifications from your CRM or helpdesk.
- Find the IP addresses or include statements for each sender. For your own mail server, note its public IP. For third-party services, look for a dedicated SPF include value in their documentation. For example, SendGrid tells you to use
include:sendgrid.net, and Google Workspace usesinclude:_spf.google.com. If you cannot find an include, use the IP address they provide. - Build your SPF record string. Start with
v=spf1. Then add each sender mechanism in any order. Useip4:YOUR.IP.ADDRESSfor IPv4,ip6:YOUR:IPV6::ADDRESSfor IPv6, andinclude:provider.comfor third-party services. End with-all(hard fail) or~all(soft fail). Example:v=spf1 ip4:203.0.113.10 include:_spf.google.com include:sendgrid.net -all - Check the 10-lookup limit. SPF records can only perform 10 DNS lookups (each
includeorredirectcounts as one, and eachaormxmechanism also counts). Count your includes and mechanisms. If you exceed 10, combine services or use a dedicated SPF flattening tool to merge them into IP addresses. - Create the TXT record in your DNS. Log into your DNS management panel. Find the section for adding new records. Choose type
TXT. In the Host/Name field, enter@(or leave it blank, depending on the provider) to apply to the root domain. In the Value/Content field, paste your entire SPF string exactly as you wrote it. Save the record. - Verify the record is published. Use a command-line tool like
nslookup -type=TXT yourdomain.comor an online SPF checker. The output should show your TXT record with the SPF string. Note: DNS propagation can take up to 48 hours, but it often completes in under an hour. - Test with a real email. Send a test email to a Gmail or Outlook address and check the email headers. Look for the
Received-SPFline. It should saypass. If it saysfailorneutral, review your record.
Common Mistakes
- Using
+allor no ending mechanism. This tells receivers that any server can send for your domain, defeating the purpose. Always use-allfor strict protection or~allfor a softer approach. - Forgetting to include all senders. Missing a third-party service will cause legitimate emails to fail SPF, landing in spam.
- Exceeding the 10-lookup limit. If you have too many includes, SPF fails permanently, and all emails may be rejected.
- Adding multiple SPF records. You can only have one TXT record that starts with
v=spf1. If you have more than one, receivers combine them and often fail the check. Remove old ones. - Using
aormxwithout specifying domains. If you useaalone, it only checks the domain's A record. If your mail server is on a different host, it will fail. Usea:mail.yourdomain.cominstead.
Tips
- Start with
~all(soft fail) when you are testing. This tells receivers to accept the email but mark it as suspicious. Once you are sure everything works, switch to-all. - Use a free SPF validation tool. Many online tools (like MXToolbox or SPF Record Checker) will show you the exact lookup count and any syntax errors.
- Keep a copy of your SPF string in a safe place. If you ever change DNS providers, you will need to re-add it.
- Review your SPF record quarterly. Services change IPs and add new ones. Update your record when you add or remove an email-sending service.
Troubleshooting
Emails are still going to spam after setting SPF. First, check the email headers for the Received-SPF line. If it says pass, SPF is working, and the issue is likely DKIM or DMARC. If it says fail, your record is missing the sending server's IP or include. If it says neutral or none, the record may not have propagated yet, or you have a syntax error.
You get a 'permanent error' in SPF checks. This usually means you exceeded the 10-lookup limit. Remove unnecessary includes or replace them with direct IP addresses. Use an SPF flattening service to compress the record.
You accidentally created two SPF records. Delete the older one. DNS providers often let you have multiple TXT records, but only one can start with v=spf1. If you have two, receivers will see a conflict and may reject all mail.
Your include is not working. Verify that the include domain actually has a valid SPF record. For example, include:sendgrid.net must resolve to a TXT record that starts with v=spf1. Use an online SPF lookup to check.
Frequently Asked Questions
Can I have multiple SPF records?
No. You can only have one TXT record that starts with v=spf1. If you have more than one, they will be combined and may cause a permanent error. Delete all but one.
What does -all vs ~all mean?
-all means hard fail: if the email comes from a server not listed, it should be rejected. ~all means soft fail: the email is accepted but marked as suspicious. Use ~all while testing, then switch to -all.
How long does SPF take to propagate?
DNS changes can take up to 48 hours, but most updates propagate within an hour. You can check with a global DNS checker to see when it is visible worldwide.
Do I need SPF if I have DKIM and DMARC?
Yes. SPF, DKIM, and DMARC work together. SPF alone is not enough, but it is a required part of email authentication. DMARC uses SPF and DKIM to decide how to handle unauthenticated mail.
What if my email provider uses a shared IP address?
Use the include mechanism provided by your email service. Do not use the shared IP directly, because it may change. The include will automatically track the current IPs.
Can I use an SPF record for subdomains?
Yes. You can create a separate SPF TXT record for each subdomain (e.g., mail.yourdomain.com). If you do not, the subdomain may inherit the parent's SPF record, which might not include the correct senders.