Email Authentication Comparison: SPF vs. DKIM vs. DMARC

A detailed technical comparison of the three major email authentication methods, their strengths, limitations, and how they work together.

Email authentication is a critical component of modern email communication, helping to prevent spam, phishing, and domain spoofing. The three primary authentication methods - Sender Policy Framework (SPF), DomainKeys Identified Mail (DKIM), and Domain-based Message Authentication, Reporting, and Conformance (DMARC) - work together to provide a comprehensive security solution. This in-depth guide compares these methods, explores their strengths and limitations, and provides step-by-step implementation guidance for securing your email infrastructure.

Understanding Email Authentication Methods

Sender Policy Framework (SPF)

SPF is an email authentication method that allows domain owners to specify which mail servers are authorized to send emails on behalf of their domain. By publishing an SPF record in the domain's DNS settings, the domain owner provides a list of IP addresses or hostnames that are permitted to send emails for that domain.

When an email is received, the receiving mail server performs an SPF check by comparing the connecting server's IP address with the SPF record of the envelope sender domain (the MAIL FROM, or Return-Path, domain), or of the HELO name when the envelope sender is empty. It does not look at the visible From header. If the IP address matches one of the authorized servers, the email passes the SPF check. If not, the email may be marked as spam or rejected altogether.

Note: SPF is a relatively simple and widely adopted authentication method, but it has some limitations. For example, on its own it does not protect the visible From address from spoofing, it does not detect content tampering, and it usually breaks when a message is forwarded. Keep the record within the limit of 10 DNS lookups.

Implementing SPF

To implement SPF for your domain, follow these steps:

  1. Identify all the mail servers that are authorized to send emails on behalf of your domain.
  2. Create an SPF record for your domain, listing the IP addresses or hostnames of the authorized servers. For example:
    v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.0/24 include:_spf.google.com -all
  3. Publish the SPF record in your domain's DNS settings as a TXT record.
  4. Test your SPF implementation using an online SPF checker such as MxToolbox, or send a test email to SpamBarometer to see the result.

DomainKeys Identified Mail (DKIM)

DKIM is an email authentication method that uses cryptographic signatures to verify the authenticity and integrity of email messages. With DKIM, the sending mail server digitally signs the email headers and body using a private key. The public key is published in the domain's DNS settings as a TXT record.

When the email is received, the receiving mail server retrieves the public key from the sending domain's DNS and uses it to verify the DKIM signature. If the signature is valid, it confirms that the signing domain took responsibility for the message and that the signed headers and body have not been altered in transit.

DKIM Advantages
  • Detects content tampering in transit
  • Usually survives forwarding, unlike SPF
  • Ties the message to a signing domain that DMARC can align with the From domain

Implementing DKIM

To set up DKIM for your domain, follow these steps:

  1. Generate a public-private key pair (2048-bit RSA is the common choice) using a tool like OpenSSL, or let your email service provider generate it for you.
  2. Configure your mail server to sign outgoing emails with the private key. The specific steps vary depending on your mail server software (e.g., Postfix, SendMail, Exchange).
  3. Publish the public key in your domain's DNS as a TXT record. The record should be named selector._domainkey.yourdomain.com, where "selector" is a unique identifier for the key.
  4. Test your DKIM implementation using an online DKIM checker such as MxToolbox, or by sending a test email and checking the DKIM result.

Domain-based Message Authentication, Reporting, and Conformance (DMARC)

DMARC is an email authentication policy that builds upon SPF and DKIM. A message passes DMARC when SPF or DKIM passes and the passing domain aligns with the domain in the visible From header; one aligned pass is enough. DMARC lets domain owners specify how receiving mail servers should handle emails that fail this check. DMARC also provides a reporting mechanism, allowing domain owners to monitor their email traffic and identify potential security issues.

With DMARC, domain owners publish a policy in their DNS settings as a TXT record. The policy specifies the desired actions for emails that fail authentication, such as marking them as spam, rejecting them, or quarantining them. The policy also includes instructions for receiving mail servers to send periodic reports about the domain's email traffic and authentication results.

The diagram below shows how a receiving server evaluates a DMARC policy:

DMARC evaluation: the receiving server runs SPF and DKIM, checks that a passing result aligns with the visible From domain, then delivers the message or applies the published policy of none, quarantine or reject.
How a receiving server applies your DMARC policy
DMARC Policy Description
p=none No action is taken on emails that fail authentication, but reports are still sent.
p=quarantine Emails that fail authentication are marked as spam or quarantined.
p=reject Emails that fail authentication are rejected outright.

Implementing DMARC

To set up DMARC for your domain, follow these steps:

  1. Ensure that you have properly implemented SPF and DKIM for your domain.
  2. Create a DMARC policy record for your domain. Start with a "none" policy to monitor your email traffic without affecting delivery. For example:
    v=DMARC1; p=none; rua=mailto:dmarc-reports@yourdomain.com; ruf=mailto:dmarc-forensics@yourdomain.com; fo=1; pct=100
  3. Publish the DMARC policy record in your domain's DNS settings as a TXT record at _dmarc.yourdomain.com.
  4. Monitor the DMARC reports you receive to identify any authentication issues or unauthorized email sources.
  5. Gradually adjust your DMARC policy from "none" to "quarantine" and eventually to "reject" as you become more confident in your email authentication setup.

Best Practices for Email Authentication

Regularly monitor your email authentication results and DMARC reports to identify potential issues and unauthorized email sources. This allows you to address problems quickly and maintain the integrity of your email communication.

When implementing DMARC, start with a "none" policy and gradually progress to "quarantine" and "reject" policies. This approach allows you to monitor the impact of your authentication policies and identify any legitimate email sources that may be inadvertently blocked.

Regularly rotate your DKIM keys to minimize the risk of key compromise. If a key is compromised, attackers could use it to sign fraudulent emails. By rotating keys periodically, you limit the potential impact of a compromised key.

Common Pitfalls and Troubleshooting

SPF Record Syntax Errors

One of the most common issues with SPF is incorrect record syntax. Ensure that your SPF record follows the proper format and includes all necessary directives. Use online tools to validate your SPF record and check for any syntax errors.

Warning: An invalid SPF record can lead to email delivery issues and may even cause your emails to be marked as spam.

DKIM Key Configuration Issues

Properly configuring your DKIM keys is essential for successful email authentication. Common issues include:

  • Incorrect key size or algorithm
  • Mismatch between the private key used for signing and the public key published in DNS
  • Incorrect DNS record format or placement

Double-check your DKIM key configuration and use online tools to validate your DKIM setup.

Incorrect DMARC Policy Alignment

DMARC needs at least one of SPF or DKIM to pass and align with the From domain. With relaxed alignment (the default), the organisational domains must match, so mail.yourdomain.com aligns with yourdomain.com; with strict alignment, they must match exactly. A common failure is a third-party sender that passes SPF and DKIM for its own domain rather than yours. Make sure every legitimate sending source signs with DKIM using your domain or uses a Return-Path on your domain.

Conclusion and Next Steps

Email authentication is a critical component of a comprehensive email security strategy. By implementing SPF, DKIM, and DMARC, organizations can protect their domains from spoofing, phishing, and other email-based threats. However, successful implementation requires careful planning, regular monitoring, and ongoing maintenance.

To get started with email authentication for your domain, follow these steps:

  1. Assess your current email infrastructure and identify all legitimate email sources.
  2. Implement SPF by creating and publishing an SPF record for your domain.
  3. Set up DKIM by generating key pairs, configuring your mail servers, and publishing the public key in DNS.
  4. Deploy DMARC by creating a DMARC policy record and publishing it in DNS.
  5. Monitor your authentication results and DMARC reports, adjusting your policies as needed.
Remember: Email authentication is an ongoing process. Regularly review your SPF, DKIM, and DMARC configurations, monitor your email traffic, and stay informed about the latest email security best practices and threats.

The comparison below summarizes what each method checks:

Side-by-side comparison: SPF checks the sending server against a DNS list, DKIM checks a cryptographic signature on the message, and DMARC ties both to the visible From domain, sets a policy and sends reports.
What SPF, DKIM and DMARC each check
Check your own email in a minute. Send one email to a test address and see your SPF, DKIM, DMARC and spam score.
Test your email
Was this guide helpful?

Topics: Deliverability, Authentication, Best Practices, Technical