How to set up an SPF record for your domain
With SPF (Sender Policy Framework), you specify in DNS which servers may send email on behalf of your domain. Receiving mail servers use it to recognize forged senders.
How an SPF record is structured
An SPF record is a TXT record on your domain that starts with v=spf1. It's followed by the allowed senders, and the record ends with a rule for all other servers.
- include:…: allow the servers of an email provider, for example include:_spf.google.com.
- ip4:… and ip6:…: allow a specific IP address.
- mx and a: allow the servers in your MX or A record.
- -all rejects all other senders; ~all marks them as suspicious. Both are fine.
- ?all (neutral) and +all (allow everyone) offer no protection.
Example
If you use several services that send email on behalf of your domain (for example your email provider and a newsletter service), put them all in one record.
v=spf1 include:_spf.google.com include:mailgun.org ~allDomain without email
Does your domain send no email at all? Then add this record. It tells receivers that any email "from" your domain is forged.
v=spf1 -allWhat SPF does and doesn't do
SPF checks the technical sender address (the envelope sender or Return-Path), not the From address the recipient sees in their email program. A scammer can therefore put their own domain in the envelope and your domain as the visible sender. Only DMARC ties the two together.
SPF also often fails for forwarded email, because the forwarding server isn't in your record. A good SPF record improves the chance that your email arrives properly, but doesn't guarantee delivery to the inbox.
Common mistakes
- Two SPF records on the same domain. That's invalid; merge them into one record.
- Forgetting to add a new email provider or newsletter service.
- More than ten DNS lookups (every include counts, as do the includes inside it). Above that, the record is invalid.
- Ending with +all, which lets anyone send email on behalf of your domain.
- "Fixing" a delivery problem by replacing -all with ?all or +all. Add the missing service to the record instead.
How SteadyHost rates SPF
- OK: one SPF record that ends in -all or ~all.
- Warning: no SPF record, or a record with ?all or +all.
- Problem: multiple SPF records, or a record that needs more than ten DNS lookups.
- SteadyHost counts the lookups of your record and of every include in it. If one of those lookups fails, we judge the record without the count.
Check your own website
A free check shows within seconds how your website is doing: availability, HTTPS and TLS, the SSL certificate, security headers, DNS and DNSSEC, domain registration and email security.
More guides
- Website down? How to find the cause
- HTTPS and redirecting HTTP to HTTPS
- How to check an SSL certificate is valid
- TLS versions: disable TLS 1.0 and 1.1
- Security headers explained, with examples
- Mixed content: http:// on an HTTPS page
- security.txt: where to report vulnerabilities
- DNS records explained: A, AAAA, MX and NS
- What is DNSSEC and how do you enable it?
- CAA record: who can issue your certificates?
- Check domain registration: status and expiry
- How to check and set up a DKIM record
- What is DMARC and how do you set it up?