SPF record (Sender Policy Framework) is an email authentication protocol designed to prevent email spoofing and enhance the deliverability of legitimate emails.
By configuring an records, domain owners can specify which mail servers are authorized to send emails on their behalf.
This helps email servers verify whether an incoming message from a domain is legitimate or forged.
Table of Contents
In this guide, we’ll dive deep into what SPF & records are, how they work, their components, how to configure them, and the impact they have on your email deliverability and security.
What is an SPF Record?
It is a type of DNS (Domain Name System) TXT record that lists the mail servers and IP addresses permitted to send emails for a domain. When an email is received, the recipient’s server checks the record of the sender’s domain to verify if the email originated from an authorized source.
Why is SPF Important?
- Prevent Email Spoofing: Email spoofing is when attackers forge email headers to make messages appear as if they’re sent from a trusted domain. SPF helps mitigate this.
- Improve Email Deliverability: Emails from unauthorized sources are more likely to be flagged as spam. SPF ensures that legitimate emails are delivered to recipients’ inboxes.
- Enhance Brand Reputation: By reducing the chances of your domain being used in phishing attacks, SPF protects your brand’s trustworthiness.
How Does SPF Work?
- Email Sent: When an email is sent from your domain, the recipient’s mail server retrieves your domain’s SPF from DNS.
- SPF Check: The recipient’s mail server compares the sending server’s IP address with the IPs listed in your SPF.
- Pass or Fail:
- If the sending IP matches the authorized IPs in your SPF, the email passes the SPF check.
- If not, the email fails the SPF check, and the recipient’s server can take action, such as marking the email as spam or rejecting it.
Components of an SPF Record
It is a DNS TXT record with specific syntax. Here’s an example:
v=spf1 ip4:192.168.0.1 include:_spf.google.com -all
Let’s break it down:
v=spf1
:- This indicates the version of SPF being used. Currently, the only valid version is
spf1
.
- This indicates the version of SPF being used. Currently, the only valid version is
ip4:192.168.0.1
:- This specifies an IPv4 address authorized to send emails on behalf of the domain.
include:_spf.google.com
:- This allows the inclusion of another domain’s SPF. For instance, if you’re using Google Workspace, this directive tells the recipient’s mail server to check Google’s SPF for authorized servers.
-all
:- This specifies the action to take when an email fails the SPF check. There are three possible qualifiers:
-all
(Fail): Emails from unauthorized servers should be rejected.~all
(SoftFail): Emails from unauthorized servers are marked as suspicious but not rejected outright.?all
(Neutral): No specific policy is applied for unauthorized servers.
- This specifies the action to take when an email fails the SPF check. There are three possible qualifiers:
How to Create an SPF Record
Creating and adding an record to your domain involves these steps:
1. Identify Your Email Sending Sources
- List all servers, services, and applications that send emails on behalf of your domain. This may include:
- Your web hosting server.
- Third-party email services like Google Workspace, Microsoft 365, or SendGrid.
- Marketing platforms like Mailchimp or Constant Contact.
2. Write the SPF Record
- Use the proper syntax to include all authorized sources. Here’s an example for a domain that uses both Google Workspace and a web hosting server.
v=spf1 include:_spf.google.com ip4:203.0.113.5 -all
3. Add the SPF Record to Your DNS
- Log in to your DNS hosting provider (e.g., Cloudflare, GoDaddy, or your web hosting control panel).
- Navigate to the DNS management section.
- Add a new TXT record with the following details:
- Name/Host: Your domain name (or
@
for the root domain). - Type: TXT
- Value: Your SPF record, e.g.,
v=spf1 include:_spf.google.com ip4:203.0.113.5 -all
- Name/Host: Your domain name (or
4. Save Changes and Verify
- Save the DNS record and allow time for it to propagate (usually a few hours).
- Use tools like MXToolbox or command-line utilities like
dig
to verify your record.
Examples of SPF Records
1. Basic SPF Record
For a domain that sends emails only from its web hosting server:
v=spf1 ip4:192.0.2.1 -all
2. Record with Multiple IPs
If emails are sent from multiple servers:
v=spf1 ip4:192.0.2.1 ip4:203.0.113.5 -all
3. Record with Third-Party Services
If you’re using Google Workspace and Mailchimp:
v=spf1 include:_spf.google.com include:servers.mcsv.net -all
4. SoftFail Policy
If you want to allow emails from unauthorized sources but mark them as suspicious:
v=spf1 ip4:192.0.2.1 ~all
SPF Record Best Practices
- Keep It Simple:
- Avoid overly complex SPF. Ensure they include all authorized sources without redundant directives.
- Limit DNS Lookups:
- SPF checks are limited to 10 DNS lookups. Avoid exceeding this limit to prevent SPF failures.
- Use the
-all
Qualifier:- For stricter enforcement, use
-all
to reject unauthorized emails outright.
- For stricter enforcement, use
- Test Before Implementation:
- Use testing tools to validate your SPF before deploying it to production.
- Monitor Changes:
- Whenever you add or remove email services, update your SPF accordingly.
SPF and Other Email Authentication Protocols
SPF works best when combined with other email authentication mechanisms like DKIM and DMARC:
- DKIM (DomainKeys Identified Mail):
- Adds a cryptographic signature to outgoing emails, verifying that the message has not been altered during transit.
- DMARC (Domain-based Message Authentication, Reporting, and Conformance):
- Defines a policy for how recipient servers should handle emails that fail SPF or DKIM checks.
A typical DMARC policy might look like this:
v=DMARC1; p=reject; rua=mailto:dmarc-reports@example.com;
Common SPF Issues and Troubleshooting
1. SPF PermError
- Cause: Exceeding the 10 DNS lookup limit.
- Solution: Simplify your SPF record or use SPF flattening services to reduce lookups.
2. Emails Still Being Spoofed
- Cause: SPF alone doesn’t prevent all spoofing attacks.
- Solution: Implement DKIM and DMARC alongside SPF for comprehensive protection.
3. SPF Record Not Found
- Cause: The SPF record hasn’t been added to DNS or was added incorrectly.
- Solution: Verify the DNS settings and ensure the record is formatted correctly.
Conclusion
SPF records are a vital component of email authentication, providing a way to protect your domain from spoofing and phishing attacks while ensuring reliable email deliverability.
By understanding how SPF works, creating accurate SPF records, and maintaining them as your email infrastructure evolves, you can safeguard your domain’s reputation and ensure your emails reach their intended recipients.
While SPF alone isn’t a silver bullet, combining it with DKIM and DMARC creates a robust defense against email fraud and ensures your domain is trusted in the email ecosystem.