SPF (Sender Policy Framework) is a DNS TXT record that tells receiving mail servers which IP addresses are allowed to send email for your domain. Setting it up correctly reduces the chance your emails land in spam and helps prevent spoofing. Before you start, you'll need access to your domain's DNS settings (usually through your domain registrar or hosting provider) and a list of all services that send email on your behalf (e.g., your web server, email marketing platform, or third-party email service).
What You'll Need
- Access to your domain's DNS management panel (e.g., Cloudflare, GoDaddy, Namecheap, cPanel, or your web host).
- A list of all IP addresses or hostnames that send email for your domain. This includes your mail server, website server, and any third-party services (like SendGrid, Mailchimp, or Google Workspace).
- Knowledge of your domain's current DNS records (to avoid overwriting an existing SPF record).
Step-by-Step
- Gather your sending sources. Make a list of every server or service that sends email from your domain. For example: your office mail server (e.g., 192.0.2.10), your website's contact form (often the web server's IP), and any email marketing service (they usually provide a hostname like
sendgrid.net). If you use Google Workspace or Microsoft 365, they have specific SPF include entries (e.g.,_spf.google.comorspf.protection.outlook.com). - Check for an existing SPF record. Use a DNS lookup tool (like MXToolbox or Google Admin Toolbox) or run
dig TXT yourdomain.comin a terminal. Look for a TXT record that starts withv=spf1. If one exists, you'll need to edit it, not add a second one (multiple SPF records can cause failures). - Build your SPF record. The basic syntax is
v=spf1 [mechanisms] ~all. Mechanisms you'll likely use:ip4:for an IPv4 address (e.g.,ip4:192.0.2.10),ip6:for IPv6,include:to add a third-party's SPF record (e.g.,include:_spf.google.com), andato allow your domain's A record IP (if your web server sends mail). Separate each with a space. End with~all(soft fail) or-all(hard fail). Start with~allto avoid rejecting legitimate mail during testing. - Create the DNS record. In your DNS panel, add a new TXT record. Set the host/name to
@(or your bare domain, e.g.,example.com). Paste your full SPF string into the value/content field. Example:v=spf1 ip4:192.0.2.10 include:_spf.google.com ~all. - Save and wait. DNS changes can take anywhere from a few minutes to 48 hours to propagate. After saving, note the time.
- Test your SPF record. After propagation (wait at least an hour, but ideally 24), use an SPF checker tool (like MXToolbox's SPF lookup) to verify the record is valid and shows no errors. Send a test email to a Gmail or Outlook address and check the message headers for
spf=pass.
Common Mistakes
- Adding a second SPF record. Having multiple TXT records that start with
v=spf1causes a permanent error. Always edit or replace the existing one. - Using
-alltoo early. If you miss a legitimate sender, hard fail will cause those emails to be rejected. Use~allinitially, then tighten to-allafter verifying all senders are listed. - Exceeding the 10-lookup limit. Each
include:,a,mx, orptrmechanism counts as a DNS lookup. If your SPF record requires more than 10 lookups, receiving servers will return apermerrorand fail the check. Keep it under 10. - Forgetting to include all sending sources. Common omissions: transactional emails from your e-commerce platform, email sent from a third-party helpdesk, or your CRM. Review your email-sending infrastructure regularly.
Tips
- Use
include:instead of listing IPs for third-party services. Their IPs can change without notice; their SPF record is updated automatically. - If you're unsure about a mechanism, use
ato allow any IP that matches your domain's A record. This is convenient if your web server sends mail for contact forms. - Keep your SPF record as short as possible. Combine IPs in a single
ip4:entry if they're in the same subnet (e.g.,ip4:192.0.2.0/24). - Monitor your SPF record after changes. Use a service like Google Postmaster Tools to see if any legitimate mail is failing SPF.
Troubleshooting
SPF validation fails after setup: Check that your record is exactly one TXT record and starts with v=spf1. Use an online SPF checker to see which mechanism is causing the failure. Common issues: missing a sender IP, a typo in an IP or include, or exceeding the 10-lookup limit. If you exceed the limit, remove unnecessary mechanisms or consolidate IPs.
Emails going to spam despite SPF pass: SPF is only one part of email authentication. You also need DKIM (DomainKeys Identified Mail) and DMARC. Implement DKIM for your sending services and set up a DMARC policy (start with p=none) to monitor. Also check your domain's reputation and ensure your content isn't spammy.
Changes not taking effect: DNS propagation can take up to 48 hours. Use a global DNS checker to see if your record is visible. If it's been longer, verify you saved the record in the correct zone and that the host is @ (not www).
You see multiple SPF records after editing: Some DNS providers allow multiple TXT records with the same name. Delete the old SPF record and ensure only one remains. You can verify with dig TXT yourdomain.com.
Frequently Asked Questions
What does ~all vs -all mean?
~all means 'soft fail' – the receiving server will mark the email as suspicious but may still accept it. -all means 'hard fail' – the email is rejected. Start with ~all to avoid blocking legitimate mail.
Can I have more than one SPF record?
No. Multiple SPF records cause a permanent error. You must have exactly one TXT record that starts with v=spf1.
How do I add SPF for Google Workspace?
Add include:_spf.google.com to your SPF record. For example: v=spf1 include:_spf.google.com ~all.
What is the 10-lookup limit?
SPF records are limited to 10 DNS lookups. Each include:, a, mx, ptr, and exists mechanism counts as one. If you exceed this, receiving servers return a permerror and SPF fails.
Does SPF stop spoofing completely?
No. SPF alone only verifies the envelope sender. To fully authenticate your domain, you should also implement DKIM and DMARC. DMARC tells receiving servers what to do if SPF or DKIM fails.
How long does SPF take to work?
DNS propagation can take from a few minutes to 48 hours. Most changes are visible within a few hours, but test after 24 hours to be safe.