Simple Mail Transfer Protocol (SMTP), the core protocol for email delivery, was never designed with security in mind. Over time, attackers have exploited its lack of authentication to launch various types of abuse, especially domain impersonation. By abusing the lack of sender authentication in the SMTP protocol, a threat actor can send an email impersonating any domain on the Internet, resulting in successful phishing and business email compromise (BEC) attacks.
To address this weakness of the SMTP protocol and to enhance the email spoofing protection, the security research community designed three email authentication protocols: Sender Policy Framework (SPF), DomainKeys Identified Mail (DKIM), and Domain-based Message Authentication, Reporting, and Conformance (DMARC). While the request for comments (RFC) specification documents theoretically explain in detail how to implement each protocol, practical implementations can lead to misconfigurations or errors that undermine security. To avoid such issues, in this article, we cover some security best practices to keep in mind when implementing each protocol and how to ensure that your implementation remains resilient.
The table below summarizes the different security best practices we will cover for each email security protocol during its setup and after.
Best practice category |
Description |
Defense in depth email security mindset |
By combining SPF, DKIM, and DMARC, you ensure defense-in-depth email protection against domain impersonation. |
SPF setup best practices |
Implementing SPF might look straightforward, but its use can get cumbersome. Best practices for SPF setup include restricting lists of IP addresses and avoiding nested SPF records. |
DKIM setup best practices |
DKIM relies on cryptography to ensure email authenticity and integrity. Since DKIM uses cryptographic keys to verify email integrity, missteps in key management or algorithm choice can weaken your implementation. You can avoid a poor DKIM implementation by following best practices such as maintaining private key hygiene and choosing cryptographically secure algorithms. |
DMARC setup best practices |
While DMARC is simpler to implement than SPF and DKIM, consuming and managing many DMARC reports can quickly get challenging and frustrating. To avoid getting overwhelmed, make use of best practices like implementing DMARC strict mode after testing and reviewing your DKIM/SPF setups. |
What comes after the setup? |
Regular maintenance should also be performed by changing the list of IPs for SPF or rotating the cryptographic material for DKIM. Reviewing DMARC reports for your domain will help you identify and thwart domain impersonation trends in time. |
The use of SPF, DKIM, or DMARC considerably improves your email security against domain impersonation, but no protocol is 100% safe from attacks. Relying on a single tool or protocol creates risk, especially in security where attackers look for weak links. That is why it is always recommended to follow a defense-in-depth approach, so that even if one layer of defense falls, other layers will still protect you. You can achieve this for email security by implementing SPF, DKIM, and DMARC in tandem, as each protocol complements the others and mitigates their respective weaknesses.
SPF works by creating a DNS TXT record for your domain where you specify a list of IP addresses, IP ranges, or domains that are authorized to send emails on behalf of your domain. For the sake of simplicity, here is an example of a basic DNS TXT record for SPF:
v=spf1 ip4:1.2.3.4 -all |
This SPF record contains the following information:
While the SPF setup seems straightforward, there are some security best practices to consider when during implementation:
While these are some common challenges for any SPF setup, keep in mind that other additional challenges might arise with the SPF implementation when you start using Microsoft 365 or Google Workspace.
DKIM is another email security protocol that helps you prevent domain impersonation by using public-key cryptography. Since DKIM setup tends to be more complex than SPF or DMARC, we’ve covered it in more depth in a separate article. In this article, we review a basic DNS TXT record for DKIM and go through some of the security best practices to keep in mind during and after the setup process:
v=DKIM1; k=rsa; p=<base_64_encoded_public_key> |
A basic DKIM record contains the following elements:
For DKIM, follow these security best practices to ensure the effectiveness of this protocol:
DMARC is the newest of the three protocols and was created to complement SPF and DKIM as well as to provide domain owners with authentication results and reports of the emails sent from their domain. DMARC relies on SPF and/or DKIM and requires that either of these two protocols already be set up for it to function properly.
Unlike SPF, DMARC information is placed on a separate DNS TXT record under _dmarc.example_domain.com and not directly under example_domain.com. A basic DMARC record would look like this:
v=DMARC1; p=none; rua=mailto:<some email address>; ruf=mailto:<some email address> |
This record contains the following fields:
Consider the following security best practices both before and after setting up DMARC:
As a best practice, we recommend a gradual approach. You can start by using p=none to create an understanding of the email delivery and collect data, followed by a light enforcement (i.e., emails might be quarantined but still delivered) by switching to p=quarantine once you have evaluated the data from the first stage. Finally, after ensuring that email delivery is not hindered by p=quarantine, you can confidently change the enforcement level to p=reject to benefit from the full protection of DMARC.
The step by step process of carefully enforcing DMARC to strict mode
Setting up SPF, DKIM, and DMARC is just the beginning, keeping them effective takes ongoing monitoring and maintenance. For example, SPF relies on a hardcoded list of IPs to work, so if your IT infrastructure changes, this might impact SPF. For example, if your organization stops using a third-party email service but forgets to remove its IP addresses from your SPF record, those IPs could eventually be recycled and assigned to someone else. If that happens, and your SPF record still lists them as authorized, a malicious actor could send spoofed emails that appear to come from your domain. That’s why it’s important to regularly review and update your SPF configuration to ensure it only includes active, trusted sources.
Similarly, DKIM might require the periodic rotation of the cryptographic material to remain secure. While this monitoring and maintenance doesn’t need to be very frequent, it still remains an essential process to ensure that your defenses are operating properly and remain secure.
Finally, one of the most important benefits of DMARC is its reporting capabilities. By regularly reviewing and analyzing DMARC reports, you can track and react in time to active attempts that impersonate your domain. However, regularly parsing XML reports, analyzing them, and extracting important insights from these reports might become overwhelming with time. That is why you should consider investing in a solution that performs all these tedious tasks for you, allowing you to only focus on visualizing the results and acting on them.
SPF, DKIM, and DMARC can greatly boost your email security, reduce the risk of domain spoofing, and ensure your emails get delivered to inboxes. During their setup, it is important to follow security best practices to avoid undermining the security benefits these protocols provide. In this article, we explored each of these protocols and some of the most important best practices to keep in mind and how to combine all three protocols for a defense-in-depth approach to email security. Remember that, once set up, regularly monitoring and analyzing the DMARC reports is necessary to maximize the security benefits of these three protocols.