SPF stops criminals from sending mail that looks like it comes from your domain

SPF (Sender Policy Framework) is a straightforward rule you publish in your domain's DNS records that tells the world which mail servers are allowed to send email on your behalf. When someone receives an email claiming to be from your domain, their mail server checks your SPF record. If the message came from a server you listed, it passes. If it came from somewhere else, the receiving server can reject it or mark it as suspicious.

Without SPF, anyone can send email that appears to come from your domain — your name, your company, your address — and most recipients will see no warning. SPF doesn't encrypt your mail or hide its contents. It straightforward prevents impersonation at the sending stage, which stops the most common email fraud: phishing attacks that trick people into clicking malicious links or handing over passwords because the message looks official.

SPF works alongside two related standards, DKIM and DMARC, which together form the modern email authentication stack. SPF is the easiest to set up and the first one most people deploy.

Key Takeaways

  • SPF is a DNS record that lists which mail servers can send email from your domain, and receiving servers check it to detect forged messages.
  • You create an SPF record by adding a single line of text to your domain's DNS settings, naming each server or service allowed to send your mail.
  • SPF alone does not may provide delivery — Gmail, Outlook, and other large providers now expect SPF, DKIM, and DMARC together to avoid spam folders.
  • If you send mail through a third-party service like Mailgun or SendGrid, that service provides the exact SPF record you need to add to your DNS.
  • SPF records are checked when ready by receiving mail servers, so changes take effect within hours once your DNS updates propagate.

How SPF records work when mail arrives

When you send an email from your domain, the receiving mail server performs a lookup. It extracts your domain name from the sender's address, queries your DNS records for an SPF entry, and reads the list of authorized servers. It then checks the IP address of the server that actually delivered the message. If that IP matches one you listed, the message passes SPF. If not, it fails.

A failed SPF check does not automatically reject the message — that decision belongs to the receiving server. Gmail might quarantine it. A corporate mail system might reject it outright. A smaller provider might deliver it but strip the sender's domain name or add a warning banner. The receiving server's policy determines the outcome, but a failed SPF check is always a red flag.

This is why SPF matters for developers: if you are sending transactional mail — password resets, order confirmations, alerts — from your process, and you do not publish an SPF record, your messages are more likely to land in spam or be rejected entirely, especially by large providers.

What goes inside an SPF record

An SPF record is a single line of text stored in your domain's DNS as a TXT record. It starts with v=spf1 (the version) and then lists mechanisms — instructions that say which servers or IP addresses are allowed to send mail.

The most common mechanisms are:

  • ip4: Authorizes a specific IPv4 address (example: ip4:192.0.2.1).
  • ip6: Authorizes a specific IPv6 address.
  • a: Authorizes the IP address of your domain's A record (useful if your mail server is your main web server).
  • mx: Authorizes the IP addresses of your domain's MX records (the servers that receive your mail).
  • include: Includes the SPF record of another domain (used when a third-party service sends mail for you).
  • ~all: A soft fail — says "any other server is not authorized, but do not reject the message" (the most common ending).
  • -all: A hard fail — says "any other server is not authorized, reject the message".

A real example: if you send mail through SendGrid, SendGrid provides you with an SPF record like v=spf1 include:sendgrid.net ~all. You copy that exact line into your DNS. When mail arrives from SendGrid claiming to be from your domain, the receiving server checks your SPF record, sees the include, looks up SendGrid's SPF record, finds SendGrid's IP address, and the message passes.

Where to add your SPF record in DNS

SPF records live in your domain registrar's DNS control panel — the same place you manage your domain's other records. Log into your registrar (GoDaddy, Namecheap, Route 53, Cloudflare, or wherever you registered your domain) and find the DNS or records section.

Create a new TXT record with these details:

  • Name or Host: Leave blank or enter @ (both mean your root domain).
  • Type: TXT.
  • Value: Paste the SPF record your mail service provided, or write your own based on the mechanisms above.
  • TTL: Leave at the default (usually 3600 seconds).

Save the record. DNS changes propagate within minutes to a few hours, though some providers take longer. You can check if your SPF record is live by using an online SPF checker tool — search "SPF record checker" and enter your domain name.

SPF limitations and why you need DKIM and DMARC too

SPF has a critical weakness: it only checks the IP address of the sending server, not the actual sender's address. A clever attacker can still forge the sender's name if they control a server you authorized. SPF also breaks when mail is forwarded — a forwarding service changes the sending server, so the forwarded message fails SPF even though it is legitimate.

This is why DKIM (DomainKeys Identified Mail) exists. DKIM cryptographically signs each message with a private key stored on your mail server. The receiving server verifies the signature using a public key in your DNS. Unlike SPF, DKIM survives forwarding and proves the message was not altered in transit.

DMARC (Domain-based Message Authentication, Reporting and Conformance) sits on top of both. It says "messages from my domain must pass SPF or DKIM, and if they fail, here is what to do with them." DMARC also sends you reports showing which messages passed or failed authentication, so you can spot problems.

Large providers like Gmail now expect all three. A message with only SPF is better than nothing, but messages with SPF, DKIM, and DMARC are far more likely to reach the inbox. If you are sending mail from an process, your mail service usually handles DKIM and DMARC setup — they provide the records you add to DNS, just like SPF.

Testing your SPF record after you add it

After you add your SPF record to DNS and it has propagated, send a test email to a Gmail account or another major provider. Open the message, click the three dots next to the sender's name, and select "Show original" or "View message source." Search for the line that says "SPF: PASS" or "SPF: FAIL".

If it says PASS, your SPF record is working. If it says FAIL, check that you copied the record correctly and that DNS has updated. Use an SPF checker tool to see what your DNS actually contains — sometimes a typo or a trailing space breaks the record.

If you are sending mail through a third-party service and SPF is failing, contact the service's support team with your domain name. They can tell you exactly which SPF record you need and help you troubleshoot if it is not working after you add it.

Frequently Asked Questions

Can I have more than one SPF record for my domain?

No. DNS allows only one SPF record per domain. If you need to authorize multiple mail services, list them all in a single SPF record using multiple include mechanisms. For example: v=spf1 include:sendgrid.net include:mailgun.org ~all.

What does the tilde (~) mean in ~all?

The tilde is a soft fail. It tells receiving servers "this message failed SPF, but I am not certain it is forged — deliver it anyway, but you can mark it as suspicious." A hard fail (-all) tells servers to reject the message outright. Most domains use ~all because it is safer — if you misconfigure your SPF record, legitimate mail still gets through.

Do I need SPF if I only receive mail, not send it?

SPF only protects outgoing mail, so if your domain never sends email, SPF does not matter. However, if you ever send transactional mail from an process, password resets, or notifications, you need SPF to prevent those messages from being rejected or marked as spam.

How long does it take for SPF to start working?

SPF is checked when ready by receiving mail servers, but your DNS record takes time to propagate. Most changes are live within an hour, but some providers take up to 24 hours. You can send a test email when ready after adding the record — it may fail at first, but will pass once DNS updates.

What if my mail server's IP address changes?

If you use ip4: in your SPF record and your server's IP changes, your SPF record becomes outdated and mail will fail. This is why using a: or mx: is safer — they automatically point to your current IP address. If you use a third-party mail service, their IP addresses rarely change, but if they do, the service notifies you and provides an updated SPF record.