Wrinkles

Everyday skincare basics, explained plainly

SPF Email Authentication: What It Is & How It Works

· 7 min read · Ingredients Explained

SPF (Sender Policy Framework) is an email authentication method that lets a domain owner publish a list of mail servers allowed to send email on that domain's behalf. When an incoming message claims to be from a domain, the receiving server checks that domain's SPF record in DNS to see if the sending IP address is on the approved list. If it is, the message passes the SPF check; if not, it can be flagged as spam or rejected. SPF is one of three core email authentication standards, alongside DKIM and DMARC, and it is the oldest and simplest of the three.

Why SPF Was Created

Email was designed in the 1970s and 1980s without any built-in way to verify that the sender address in a message actually belongs to the person or system sending it. This gap made it trivial for anyone to forge the "From" address. By the early 2000s, spam and phishing attacks that used fake sender addresses had become a serious problem. SPF was proposed in 2003 by Meng Weng Wong and Mark Lentczner, and it was published as an experimental RFC in 2004. It was later standardized in 2014 as RFC 7208. The core idea was to give domain owners a way to say, "These IP addresses are allowed to send mail for my domain."

How SPF Works: The Mechanics

SPF relies on a special DNS record called a TXT record. A domain owner publishes a record that looks something like this:

example.com. TXT "v=spf1 ip4:192.0.2.1 ip4:192.0.2.2 include:_spf.google.com -all"

When a mail server receives a message, it performs these steps:

  1. Extract the domain from the envelope sender address (the MAIL FROM command in SMTP, not necessarily the visible From header).
  2. Look up the SPF record for that domain in DNS.
  3. Parse the record and check the sending server's IP address against the listed mechanisms (ip4, ip6, include, etc.).
  4. Return a result: Pass, Fail, Softfail, Neutral, None, or Temperror.
  5. Apply the domain's own receiving policy (e.g., reject or quarantine messages that fail SPF).

The record above says that IPs 192.0.2.1 and 192.0.2.2 are allowed, and that any other IP should fail (-all). The "include" mechanism pulls in the SPF record of another domain, which is useful when using a third-party email service.

SPF Mechanisms and Qualifiers

SPF records are built from mechanisms that match the sending IP, and qualifiers that tell the receiver what to do if a match occurs. The main mechanisms are:

  • ip4 – matches a specific IPv4 address or range (e.g., ip4:192.0.2.0/24).
  • ip6 – matches an IPv6 address or range.
  • include – pulls in another domain's SPF record (e.g., include:_spf.example.net).
  • a – matches if the sending IP is one of the domain's A records.
  • mx – matches if the sending IP is one of the domain's MX servers.
  • all – matches every IP. Usually written as -all (fail) or ~all (softfail).

Qualifiers are prefixes that determine the result: + (pass, default), - (fail), ~ (softfail), and ? (neutral). A typical record ends with -all to indicate that any IP not explicitly allowed should fail. Softfail (~all) is a gentler warning that is often used during testing.

Setting Up SPF: Steps and Best Practices

To implement SPF for your domain, follow these steps:

  1. List all the IP addresses and third-party services that legitimately send email for your domain (your own mail server, your web hosting, your email marketing service, etc.).
  2. Create a TXT record in your DNS zone starting with v=spf1.
  3. Add mechanisms for each sender (e.g., ip4:203.0.113.5, include:spf.mandrillapp.com).
  4. End the record with -all to reject all other senders, or ~all if you are still testing.
  5. Publish the record and wait for DNS propagation (usually a few minutes to a few hours).
  6. Test your record using an SPF validation tool or by sending a test email to a mailbox that shows authentication results.

One common mistake is exceeding the 10-DNS-lookup limit. Each include, a, and mx mechanism can trigger DNS lookups, and the SPF specification caps the total at 10 to prevent denial-of-service attacks. If you hit the limit, consolidate your record or use a smaller number of includes.

Common SPF Problems and Misconceptions

A frequent issue is that SPF fails for messages sent through a third-party service that you forgot to include. For example, if you use a newsletter service but only list your own server's IP, the newsletter's IP will fail SPF. The fix is to add the service's include mechanism to your record.

Another misconception is that SPF checks the visible "From" address in the email header. In reality, SPF checks the envelope sender (the MAIL FROM command). This is why a message can pass SPF even if the From header shows a different address. That is also why SPF alone is not enough to prevent spoofing of the display name or the From header.

SPF also has a known weakness: it only verifies the sending IP, not the actual identity of the sender. An attacker can set up their own domain and send mail with a forged From header that looks like your domain, but the SPF check on the envelope will fail. However, because many mail clients do not display the envelope sender, users can still be fooled. This is why SPF is usually combined with DKIM and DMARC.

SPF vs. DKIM vs. DMARC

SPF, DKIM, and DMARC are complementary, not interchangeable. Here is how they differ:

  • SPF – verifies that the sending IP is allowed by the domain's DNS record. It is easy to set up but can break when mail is forwarded.
  • DKIM – uses a digital signature attached to the email to verify that the message was not altered in transit and that it came from a server holding the domain's private key. It survives forwarding better than SPF.
  • DMARC – tells receiving servers what to do with messages that fail SPF or DKIM, and it also aligns the From domain with the authenticated domains. DMARC is the policy layer that ties SPF and DKIM together.

In practice, you should implement all three. SPF alone is not enough to stop spoofing, but it is a necessary foundation.

Safety and Security Considerations

SPF is a security measure, but it has limitations. It does not encrypt email, nor does it verify the content. It only helps with sender authentication. Also, SPF can cause legitimate mail to be rejected if your record is misconfigured—for example, if you forget to include a third-party sender or if you use -all too aggressively. Always test your SPF record before applying a hard fail policy.

If you are not sure which IPs send mail for your domain, check your email headers from messages you know are legitimate. The "Received from" lines will show the sending IPs. You can also use free online SPF lookup tools to see what your current record looks like.

Frequently Asked Questions

Does SPF stop all email spoofing?

No. SPF only checks the envelope sender, not the visible From header. An attacker can still forge the From header to look like your domain. SPF is most effective when combined with DKIM and DMARC, which together provide stronger authentication and a policy for handling failures.

What does "SPF fail" mean in an email header?

It means the sending IP address was not listed in the SPF record of the domain in the envelope sender. The receiving server may still deliver the message, but it will mark it as suspicious. If you see an SPF fail on your own sent mail, it usually means your SPF record is missing an IP or include.

How many SPF records can a domain have?

Only one. If you publish multiple SPF TXT records, receiving servers may treat it as a permanent error, and the SPF check will fail. If you need to change your record, edit the existing one rather than adding a new one.

What is the difference between -all and ~all?

-all means "fail"—any IP not explicitly allowed is rejected. ~all means "softfail"—the message is accepted but marked as suspicious. Softfail is useful during testing, but for production you should use -all to maximize protection.

Can SPF cause email delivery problems?

Yes. If your SPF record is too strict or missing a legitimate sender, your emails may be rejected or marked as spam. Always include all your sending IPs and test before applying -all. Also, be aware that email forwarding can break SPF because the forwarding server's IP is not in the original domain's record.

In this article
  1. Why SPF Was Created
  2. How SPF Works: The Mechanics
  3. SPF Mechanisms and Qualifiers
  4. Setting Up SPF: Steps and Best Practices
  5. Common SPF Problems and Misconceptions
  6. SPF vs. DKIM vs. DMARC
  7. Safety and Security Considerations
  8. Frequently Asked Questions