Skip to main content
All CollectionsEmail Authentication Protocols
Understanding SPF SoftFail and HardFail After Flattening
Understanding SPF SoftFail and HardFail After Flattening

Understand SPF SoftFail and HardFail after flattening, their impact on email authentication, and best practices for effective SPF management.

Updated over a month ago

Sender Policy Framework (SPF) is a crucial email authentication protocol designed to prevent email spoofing and phishing attacks. When an email fails SPF validation, it can result in different failure mechanisms, such as SoftFail (~all) or HardFail (-all). These results determine how receiving mail servers treat emails that fail SPF checks. However, when SPF flattening is applied, it can inadvertently impact SPF evaluations, leading to unexpected SoftFail or HardFail responses.

In this article, we’ll dive deep into:

  • How SPF works

  • The differences between SoftFail and HardFail

  • The impact of SPF flattening

  • Best practices for SPF record management

  • Troubleshooting SPF failures with examples


How SPF Works

SPF is a DNS-based email authentication mechanism that allows domain owners to specify which mail servers are authorized to send emails on their behalf. When a recipient’s mail server receives an email, it performs an SPF check by querying the sender’s domain’s SPF record.

SPF Record Structure

An SPF record is a TXT record in a domain’s DNS configuration. Below is an example:

v=spf1 ip4:192.168.1.1 include:_spf.google.com -all

Key Components:

  • v=spf1: Identifies this as an SPF record.

  • ip4:192.168.1.1: Authorizes this IP to send emails.

  • include:_spf.google.com: References Google’s SPF records.

  • -all: Specifies a HardFail for unauthorized senders.


SoftFail (~all) vs. HardFail (-all)

  1. SoftFail (~all)

A SoftFail (~all) means that the domain owner prefers to allow emails from unauthorized sources but marks them as suspicious. The receiving mail server may still accept the email but could deliver it to the spam folder.

Example SPF Record:

v=spf1 ip4:192.168.1.1 include:_spf.google.com ~all

Mail Server Behavior:

  • If an email originates from an unauthorized IP, the recipient's server marks it as a SoftFail.

  • The email may still be delivered but could be flagged as spam.

2. HardFail (-all)

A HardFail (-all) indicates that only explicitly listed sources are allowed to send emails. Any email from an unauthorized source will be rejected outright.

Example SPF Record:

v=spf1 ip4:192.168.1.1 include:_spf.google.com -all

Mail Server Behavior:

  • If an email originates from an unauthorized IP, the recipient’s server will reject it.

  • The sender will receive a bounce-back message indicating SPF failure.


The Impact of SPF Flattening on Failures

SPF flattening is the process of replacing include statements with direct IP addresses to reduce DNS lookups and avoid the 10-lookup limit. While this helps prevent lookup limit errors, it can introduce unexpected SoftFail or HardFail results.

How SPF Flattening Works

Before Flattening:

v=spf1 include:_spf.google.com include:_spf.sendgrid.net -all

After Flattening:

v=spf1 ip4:192.168.1.1 ip4:203.0.113.5 -all

Problems Caused by Flattening:

  1. Outdated IPs: If third-party providers change their IPs, flattened SPF records become outdated, leading to unintended SPF failures.

  2. Unexpected HardFail: If an updated provider IP isn’t included, legitimate emails can be rejected.

  3. Unintended SoftFail: Some flattened IPs might not match the original SPF logic, causing email classification issues.


Troubleshooting SPF Failures After Flattening

When emails fail SPF checks, it is essential to diagnose the issue systematically.

Step 1: Verify the SPF Record

Use the following command to check an SPF record:

nslookup -type=TXT example.com

Or use online SPF lookup tools such as:

  • MXToolbox

  • Google Admin Toolbox

Step 2: Analyze SPF Failure Reports

If DMARC is enabled, use DMARC reports to identify failed SPF checks. Example DMARC policy:

v=DMARC1; p=quarantine; rua=mailto:[email protected];

Step 3: Check Email Headers

Analyze email headers to determine SPF authentication results. Look for headers like:

Received-SPF: softfail (example.com: domain of [email protected] does not designate 203.0.113.5 as permitted sender)

Step 4: Adjust SPF Policies

  • If SPF failures occur due to outdated IPs, update the SPF record with the latest provider IPs.

  • If flattening caused unintentional HardFails, consider using ~all instead of -all to prevent rejection.


Best Practices for SPF Record Management

  1. Limit SPF Flattening: Avoid excessive flattening to prevent stale IPs.

  2. Use SPF Macros: Utilize macros to dynamically resolve IPs.

  3. Monitor SPF Reports: Leverage DMARC for SPF failure insights.

  4. Use a Secondary SPF Policy: Implement _spf.example.com to store extended SPF configurations.


FAQs

Q1: Why did SPF flattening cause my emails to SoftFail?

Flattening can introduce outdated or missing IPs, causing unintended SoftFail responses.

Q2: Can I use both SoftFail and HardFail in my SPF record?

No, you must choose one. However, you can use ~all for testing and later switch to -all when confident.

Q3: How can I update SPF records dynamically?

Use a service like SPF flattening tools that update IPs dynamically or leverage SPF macros.

Q4: What happens if my SPF record exceeds the 10-lookup limit?

SPF validation fails, potentially leading to email rejection or non-compliance with authentication policies.


Conclusion

SPF flattening can optimize SPF records but may introduce SoftFail or HardFail issues due to outdated IPs. Understanding how SPF responses impact email deliverability helps organizations maintain effective email authentication.

By leveraging best practices, monitoring SPF records, and using dynamic SPF management solutions, businesses can ensure reliable email authentication and prevent unexpected SPF failures.

Did this answer your question?