SPF Record Setup & Fix Guide
In this article
SPF (Sender Policy Framework) is a DNS record that tells receiving mail servers which IP addresses are allowed to send email for your domain. It prevents spammers from forging your domain in the "From" address, improving deliverability and reducing the chance your legitimate emails land in spam. This guide covers creating a correct SPF record from scratch and fixing common problems when emails start failing or bouncing.
What You'll Need
- Access to your domain's DNS management panel (usually at your domain registrar or web hosting provider).
- A list of all services that send email on your behalf (e.g., your web server's IP, your email provider like Google Workspace or Microsoft 365, or third-party services like Mailchimp or SendGrid).
- Basic understanding of DNS records (A, MX, TXT).
- Optional: a tool like
nslookupor an online SPF checker to verify your record.
Step-by-Step
- Identify all email senders for your domain. Make a list of every system that sends email using your domain. This includes your own mail server (if you have one), your email hosting provider, and any third-party services (newsletters, transactional email, CRM, etc.). If you miss one, that service's emails may fail SPF checks.
- Find the IP addresses or hostnames of those senders. For your own server, you'll need its public IP address. For third-party services, they usually provide an SPF include directive (e.g.,
include:spf.mandrillapp.com) or a list of IPs in their documentation. - Construct your SPF record. Start with the version tag
v=spf1. Then add mechanisms for each sender in this order (order matters):ip4:203.0.113.10– allows a specific IPv4 address.ip6:2001:db8::10– allows a specific IPv6 address.include:thirdparty.com– includes the SPF record of another domain (used for services like Google, Microsoft, or SendGrid).a– allows the IP address of your domain's A record.mx– allows the IP addresses of your domain's MX records.
-allto reject all other senders. For example:v=spf1 ip4:203.0.113.10 include:_spf.google.com -all. - Add the record to your DNS. In your DNS management panel, create a new TXT record. The host/name field should be either blank,
@, or your domain name (depending on your provider). The value field should be the full SPF string you constructed. Save the record. - Wait for DNS propagation. DNS changes can take anywhere from a few minutes to 48 hours to propagate worldwide, though it's usually faster. Check after an hour or two.
- Verify your SPF record. Use an online SPF checker or run a command like
nslookup -type=TXT yourdomain.com(ordig TXT yourdomain.comon Linux/macOS). The output should show your SPF record as a TXT record. - Test with a real email. Send an email from each of your sending services to a test address (e.g., Gmail) and check the email headers for "Received-SPF: pass" (or similar). Most major providers include this in the raw message source.
Common Mistakes
- Using
+allinstead of-all. This allows anyone to send as your domain, which defeats the purpose. Use-allfor strict rejection, or~allfor a soft fail if you're still testing. - Having more than one SPF record. DNS only allows one TXT record that starts with
v=spf1. If you have multiple, receiving servers may reject or ignore them. Combine them into a single record. - Exceeding the 10 DNS lookup limit. SPF records can only perform 10 DNS lookups (each
include,a,mx, andptrcounts). If you exceed this, the SPF check fails. Useip4entries instead ofincludewhere possible, and avoid redundant includes. - Forgetting to include all senders. If you add a new email service and don't update SPF, its emails will fail. Keep a list and review it periodically.
- Using uppercase letters. SPF mechanisms are case-insensitive, but it's best practice to use lowercase to avoid confusion.
Tips
- Start with
~all(soft fail) when testing. This tells receiving servers that mail from unlisted senders is suspicious but not definitively spam. Once you're confident, switch to-all. - Use
includefor third-party services. Instead of copying their IP addresses, use theincludedirective. This way, if they change their IPs, you don't have to update your record. - Keep your SPF record short. The fewer mechanisms, the easier it is to debug and the less likely you'll hit the lookup limit.
- Monitor your email deliverability. Use tools like Google Postmaster Tools or Microsoft's Sender Dashboard to see if your emails are being marked as spam.
- Document your SPF record. Save a copy of the record and the date it was last updated. This helps when troubleshooting later.
Troubleshooting
Emails are failing SPF checks. First, verify your SPF record is correct using an online checker. Common issues: a missing sender, a typo in the record, or exceeding the 10-lookup limit. Check the email headers of a failed message to see which IP address is failing and add it to the record.
SPF record is not showing up. DNS propagation can take time. If it's been more than 48 hours, check that you added the record to the correct domain (not a subdomain) and that you used a TXT record type, not an SPF type (older style, now deprecated).
Getting "permanent error" from SPF checkers. This usually means the record is malformed. Check for extra spaces, missing v=spf1, or an empty include. Use a validator to pinpoint the issue.
One of your services is not sending. If you recently added a new service and emails are bouncing, add its IP or include directive to your SPF record. Remember to wait for propagation before testing again.
SPF passes but emails still go to spam. SPF is just one part of email authentication. Check your DKIM and DMARC settings. If you don't have DMARC, set one up to tell receivers what to do with unauthenticated mail.
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, receiving servers may reject them or only use one, causing unpredictable results. Combine them into a single record.
What does -all vs ~all mean?
-all means "hard fail" – any sender not listed is rejected. ~all means "soft fail" – the message is marked as suspicious but not rejected. Use -all for production, ~all when testing.
How do I know if my SPF record is working?
Send a test email to an address you control (e.g., Gmail). Open the raw message headers and look for a line like "Received-SPF: pass" (or "softfail" or "fail"). If it says "pass", your record is working for that sender.
What is the 10 lookup limit?
SPF records can only trigger a maximum of 10 DNS lookups. Each include, a, mx, and ptr mechanism counts as one. If you exceed 10, the SPF check fails. Use ip4 entries to reduce lookups.
Do I need SPF if I have DKIM and DMARC?
Yes. SPF, DKIM, and DMARC work together. SPF verifies the sending server's IP, DKIM verifies the message signature, and DMARC tells receivers what to do if either fails. All three improve deliverability and security.
How long does it take for SPF changes to take effect?
DNS propagation typically takes 1-48 hours, but it's often faster. You can check with online tools that query authoritative DNS servers directly to see your record immediately.