Email authentication is a critical component of modern email security, helping to protect both senders and recipients from spoofing, phishing, and other malicious activities. In this comprehensive guide, we'll dive deep into the three main email authentication protocols - SPF, DKIM, and DMARC - explaining what they are, how they work together, and best practices for implementing them effectively to secure your email communications.
What is Email Authentication?
Email authentication refers to a set of techniques and protocols used to verify the identity of an email sender and ensure that the email has not been altered in transit. Without proper authentication, it's relatively easy for attackers to send emails that appear to come from a trusted source, tricking recipients into revealing sensitive information, downloading malware, or falling victim to other scams.
The three main email authentication protocols are:
- SPF (Sender Policy Framework): Specifies which mail servers are authorized to send email on behalf of a domain
- DKIM (DomainKeys Identified Mail): Uses cryptographic signatures to verify that an email message was sent from an authorized source and has not been altered
- DMARC (Domain-based Message Authentication, Reporting, and Conformance): Builds upon SPF and DKIM to provide a clear policy for email authentication and reporting
The following diagram provides a high-level overview of how SPF, DKIM, and DMARC work together to authenticate email messages:
SPF: Sender Policy Framework
SPF is a DNS-based email authentication method that allows domain owners to specify which mail servers are permitted to send email on their behalf. By publishing an SPF record in their DNS settings, domain owners can help prevent unauthorized parties from sending emails that appear to originate from their domain.
How SPF Works
- A domain owner publishes an SPF record in their DNS settings, specifying which mail servers are authorized to send email for the domain.
- When an email is received, the receiving mail server looks up the SPF record of the envelope sender domain (the MAIL FROM, also shown as the Return-Path) or, if that is empty, the HELO name. It does not check the visible From address.
- The receiving server compares the IP address of the sending mail server to the list of authorized servers in the SPF record.
- If the sending server's IP is listed in the SPF record, the email passes SPF authentication. If not, the email fails SPF and may be flagged as suspicious.
Here's a simple example of an SPF record:
example.com IN TXT "v=spf1 ip4:192.0.2.0/24 ip6:2001:db8::/32 include:example.net -all"
This SPF record specifies that only servers with IP addresses in the ranges 192.0.2.0/24 or 2001:db8::/32, as well as any servers listed in the SPF record for example.net, are authorized to send email for the domain example.com. The -all at the end indicates a hard fail for any other servers attempting to send email for this domain.
DKIM: DomainKeys Identified Mail
DKIM is an email authentication protocol that uses cryptographic signatures to verify that an email message was sent from an authorized source and has not been altered in transit. By signing emails with a private key and publishing the corresponding public key in the domain's DNS, email senders can provide recipients with a way to verify the authenticity of their messages.
How DKIM Works
- The email sender generates a public-private key pair and publishes the public key in their domain's DNS as a DKIM record.
- When sending an email, the sender's mail server uses the private key to create a digital signature of the email content and headers.
- The signature is added to the email headers as a DKIM-Signature field.
- Upon receiving the email, the recipient's mail server retrieves the sender's public key from their DNS and uses it to verify the DKIM signature.
- If the signature is valid, the email passes DKIM authentication, confirming that it was sent from an authorized source and has not been modified. If the signature is invalid or missing, the email fails DKIM.
Here's an example of a DKIM signature header:
DKIM-Signature: v=1; a=rsa-sha256; d=example.com; s=default; c=relaxed/relaxed; q=dns/txt; t=1617227164; h=from:to:subject:message-id:date:mime-version:content-type; bh=MjFhOTQzMjU2YThjZGU3NTk5MjhiNjA1ODg1MjI0NDA=; b=aIZW8xXqXTkMm0R7lz2ZnKcT7e9kVFOOJLSpJG1fWEsOiX5zs6OU5lXxOKPmSmXHgI9z0 w8f3U0GHPyyGc6yaTROgr5CrmRpgg9gyCmN+oAYXN+H2Aqyz9EE4GWzBNa0Xrpvwri6Af 4gMJzmp5RjRfUq8kWTE1j9oBdFcVDggyE=
Implementing DKIM
To implement DKIM for your domain, follow these steps:
- Generate a public-private key pair using a tool like OpenSSL.
- Publish the public key in your domain's DNS as a TXT record with a selector prefix (e.g.,
default._domainkey.example.com). - Configure your mail server to sign outgoing emails using the private key.
- Test your DKIM implementation using a tool like MXToolbox or mail-tester.com.
Here's an example of a DKIM DNS record:
default._domainkey.example.com IN TXT "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDHEfMCPyTS2ImOv5wN9lRnePgcq0lQ6i9Rd5k1JHto/AzdPexDQ8bF4Tm0PtWFmHDQ5wRnJXqNxDoVnx8EHFoRZrJU7N5wDVyKXNKsIQdLVqNPLLF9Bjb7uHAVVlFZymaLwVxqWdORKJ5Dn6oNMDuSBpKhNFmBc3UNo6lT3HNKQIDAQAB"
SPF and DKIM: Better Together
While SPF and DKIM are powerful tools on their own, they work best when used together. SPF verifies the sender's identity at the server level, while DKIM verifies the authenticity and integrity of the email content itself. By implementing both, you can provide a more comprehensive level of email authentication and security.
DMARC: Tying It All Together
DMARC (Domain-based Message Authentication, Reporting, and Conformance) is an email authentication protocol that builds upon SPF and DKIM to provide domain owners with a clear way to specify their email authentication policies and receive reports on the results.
How DMARC Works
- Domain owners publish a DMARC policy in their DNS as a TXT record.
- When an email is received, the recipient's mail server performs SPF and DKIM checks. The message passes DMARC if at least one of them passes and aligns with the domain in the visible From address.
- If the message fails DMARC, the receiving server applies the domain's policy (deliver, quarantine, or reject). Receivers that support reporting send the domain owner regular aggregate reports summarising the results.
- Domain owners can use DMARC reports to monitor their email authentication results and identify potential security issues.
Here's an example of a DMARC record:
_dmarc.example.com IN TXT "v=DMARC1; p=reject; rua=mailto:dmarc-reports@example.com; ruf=mailto:dmarc-forensics@example.com; fo=1; adkim=s; aspf=s;"
This DMARC record specifies the following policies:
p=reject: Emails that fail DMARC (neither SPF nor DKIM passes with alignment) should be rejectedrua=mailto:dmarc-reports@example.com: Aggregate reports should be sent to the specified email addressruf=mailto:dmarc-forensics@example.com: Forensic (failure) reports should be sent to the specified email address. Many large mailbox providers don't send these, so don't rely on them.fo=1: A failure report should be generated if either SPF or DKIM fails to produce an aligned passadkim=sandaspf=s: Strict alignment should be used, so the DKIM and SPF domains must exactly match the From domain. The default, relaxed alignment, only requires the same organisational domain (somail.example.comaligns withexample.com).
Implementing DMARC
To implement DMARC for your domain, follow these steps:
- Ensure that you have SPF and DKIM properly set up for your domain.
- Decide on your DMARC policy (e.g.,
none,quarantine, orreject) and reporting preferences. - Create a DMARC record with your chosen policy and reporting settings, and publish it in your DNS as a TXT record at
_dmarc.yourdomain.com. - Monitor your DMARC reports to track your email authentication results and identify any issues.
none policy and gradually move to quarantine and reject as you gain confidence in your SPF and DKIM setup. This can help you avoid accidentally blocking legitimate emails.
Best Practices for Email Authentication
To ensure the most effective email authentication and security, consider the following best practices:
- Implement SPF, DKIM, and DMARC for all domains you use to send email
- Make sure SPF or DKIM (ideally both) aligns with your From domain; relaxed alignment is fine for most senders, so only use strict alignment if you need it
- Monitor your DMARC reports regularly and act on any issues identified
- Keep your SPF and DKIM records up to date as your email infrastructure changes
- Use strong, unique DKIM keys for each domain and rotate them periodically
- Educate your users about email security best practices, such as identifying and reporting suspicious emails
Conclusion and Next Steps
Email authentication is a crucial aspect of modern email security, helping protect both senders and recipients from spoofing, phishing, and other email-based threats. By implementing SPF, DKIM, and DMARC, you can significantly improve your email security posture and protect your reputation as an email sender.
To get started with email authentication, follow these steps:
- Assess your current email infrastructure and identify all authorized mail servers and sending domains
- Implement SPF by creating SPF records for each sending domain
- Set up DKIM by generating key pairs, publishing public keys in DNS, and configuring your mail servers to sign outgoing emails
- Publish a DMARC record with a
p=nonepolicy to start monitoring your email authentication results - Gradually move to a
p=quarantineand then ap=rejectpolicy as you refine your SPF and DKIM configuration
Authentication is no longer optional for bulk senders: since 2024 Gmail and Yahoo require SPF, DKIM and DMARC for anyone sending large volumes to their users. Once your records are in place, send a test email to SpamBarometer to confirm that SPF, DKIM and DMARC all pass and align, and recheck whenever you add a new sending service.