How to set up SPF (Sender Policy Framework)

Last updated: October 27, 2026

SPF is a DNS TXT record that lists which servers are allowed to send mail for your domain. When a receiving server gets a message claiming to be from you, it looks up your SPF record and checks whether the connecting IP is authorized. The result feeds directly into DMARC alignment and into the spam decision of every major mailbox provider.

A domain gets exactly one SPF record — one TXT record starting with v=spf1 at the domain root. Multiple SPF records make the check fail with a permanent error, which is worse than having none. Everything you authorize — your mail provider, your marketing ESP, your ticketing system — must be merged into that single record.

SPF alone does not stop spoofing (it breaks on forwarding, which is why DKIM and DMARC exist), but a missing or malformed record is still one of the most common reasons legitimate mail lands in spam. Setup takes ten minutes; verification takes one test email.

Not sure if this affects you? Run a free domain audit and see the exact check result.

Run the free domain check

Step by step

General procedure

  1. Inventory every service that sends mail as your domain: mailbox provider (Google/Microsoft), marketing ESP, transactional ESP, CRM, helpdesk, your own servers.
  2. Find each provider's include mechanism in their docs (e.g. include:_spf.google.com). Prefer include over listing IPs yourself — providers change their ranges.
  3. Build one record: v=spf1 followed by the mechanisms, ending with -all (strict) or ~all (softfail).
  4. Publish it as a TXT record at the domain root (@) with a low TTL (300–3600s) while you test.
  5. Send a test email through each provider and confirm spf=pass in Authentication-Results.

Google Workspace

  1. Use include:_spf.google.com. That single include covers all Gmail outbound IPs.
  2. Typical record if Google is your only sender: v=spf1 include:_spf.google.com -all.

Microsoft 365

  1. Use include:spf.protection.outlook.com.
  2. If you also run on-prem Exchange or hybrid, add its public IPs explicitly with ip4: mechanisms before the include.

SendGrid / Mailgun / Amazon SES

  1. SendGrid: include:sendgrid.net (shown during domain authentication).
  2. Mailgun: include:mailgun.org. SES: include:amazonses.com.
  3. Each ESP documents whether it wants its include on your root domain or on a subdomain it gave you — follow their panel; the MAIL FROM (Return-Path) domain is what SPF actually checks, and ESPs often use their own subdomain for bounces, which is fine and expected.

Your own server (Postfix/any VPS)

  1. Add ip4:203.0.113.10 (your server's public IPv4) and ip6: if you send over IPv6.
  2. Make sure the HELO hostname and PTR record are consistent too — receivers cross-check more than SPF.

Copy-paste examples

Google Workspace only, strict
@  TXT  "v=spf1 include:_spf.google.com -all"
Google Workspace + SendGrid + one own server
@  TXT  "v=spf1 include:_spf.google.com include:sendgrid.net ip4:203.0.113.10 -all"
Microsoft 365 with softfail while testing
@  TXT  "v=spf1 include:spf.protection.outlook.com ~all"

Common mistakes

  • Two TXT records starting with v=spf1 — SPF permerror, treated as fail. Merge them into one.
  • More than 10 DNS lookups (includes count recursively) — SPF permerror again. Fix with SPF flattening (see our flattening guide).
  • Using +all or ?all — authorizes everyone or nothing-useful; effectively disables SPF.
  • Forgetting an ESP, then locking -all — that provider's mail starts failing. Audit before you tighten.
  • Using the ptr mechanism — deprecated in RFC 7208, slow and unreliable; remove it.
  • Testing only from the webmail UI — SPF is evaluated on the connecting IP of each sending path; test every ESP separately.

FAQ

Should I use -all or ~all?

End state should be -all (fail): unauthorized senders are definitively rejected by the check. Use ~all (softfail) only during rollout while you confirm every legitimate source is listed. DMARC enforcement (p=quarantine/reject) matters more than the all mechanism once DKIM is also in place.

SPF passes but mail still fails DMARC — why?

DMARC needs alignment: the domain SPF authenticated (the Return-Path domain) must match the From header domain. ESPs often bounce through their own domain, so SPF passes for esp-domain.com while your From is yourdomain.com — unaligned. That is normal; DKIM alignment covers you. See our DMARC alignment guide.

How long does an SPF change take to work?

As long as the old record's TTL. With TTL 3600, receivers may cache the old record for an hour. Lower the TTL a day before planned changes.

Do subdomains need their own SPF records?

SPF is evaluated per domain in the MAIL FROM address. If you send as newsletter.example.com, that subdomain needs its own record. Subdomains do not inherit the root record.

Can SPF alone stop spoofing of my domain?

No. Forwarded mail breaks SPF, and SPF says nothing about the visible From header. You need DKIM (cryptographic signature) and DMARC (alignment + policy) for real anti-spoofing.

What is the redirect= modifier and should I use it?

redirect= hands the whole SPF policy to another domain (v=spf1 redirect=_spf.example.com). It is handy when several of your domains must share one centrally managed policy: each domain's record is a one-line redirect and you edit the target once. It counts as a lookup and cannot be combined with other mechanisms — it replaces them entirely. For a single primary domain, a plain record is simpler.

Fixed it? Prove it.

Send a test email and watch every check go green.

Send a test email to verify the fix

Related guides