HackCert
Intermediate 12 min read May 25, 2026

Email Authentication Guide: Using SPF, DKIM, and DMARC to Stop Spoofing

Learn how to properly configure SPF, DKIM, and DMARC to authenticate your domains and protect your organization from email spoofing and phishing attacks.

Mohammad Saiful Islam
Incident Responder
share
Email Authentication Guide: Using SPF, DKIM, and DMARC to Stop Spoofing
Overview

Email remains the primary communication channel for global business. Consequently, it is also the primary attack vector for cybercriminals. The foundation of most email-based attacks—whether they are phishing campaigns, Business Email Compromise (BEC), or malware distribution—relies on deception. Specifically, attackers exploit the inherent lack of authentication in the original Simple Mail Transfer Protocol (SMTP) to "spoof" email addresses. They send malicious emails that appear to originate from a trusted entity (like your CEO, a primary vendor, or your IT department), tricking users into revealing credentials or authorizing fraudulent wire transfers.

To combat this massive vulnerability, the cybersecurity and internet infrastructure communities developed three critical email authentication protocols: Sender Policy Framework (SPF), DomainKeys Identified Mail (DKIM), and Domain-based Message Authentication, Reporting, and Conformance (DMARC). When implemented correctly and in tandem, these protocols mathematically prove the origin of an email and provide clear instructions to receiving mail servers on how to handle fraudulent messages. This technical guide will deconstruct how these protocols function and how to configure them to protect your organization's digital identity.

The Problem: How Email Spoofing Works

To understand the solution, we must briefly understand the flaw in SMTP. When an email is sent, there are two different "From" addresses involved:

  1. The Envelope Sender (Return-Path or MailFrom): This is the address used by the mail servers to route the message and return bounce notifications. It is usually hidden from the end-user.
  2. The Header Sender (From: address): This is the address that the recipient actually sees in their email client (e.g., Outlook or Gmail).

In a spoofing attack, a cybercriminal uses their own infrastructure (or a compromised server) to send an email. They set the Envelope Sender to their own domain (so the email routing works), but they forge the Header Sender to be [email protected]. Without authentication protocols, the receiving mail server has no way to verify if the server that sent the email is actually authorized to send mail on behalf of yourcompany.com.

1. Sender Policy Framework (SPF)

SPF is the first line of defense. It acts as a public guest list for your domain. It allows a domain owner to publish a list of IP addresses and mail servers that are officially authorized to send email on their behalf.

How SPF Works

SPF is implemented by adding a specific TXT record to your domain's DNS settings. When a receiving mail server receives an email claiming to be from yourcompany.com (specifically checking the Envelope Sender), it performs a DNS lookup for the SPF record of yourcompany.com.

The server checks if the IP address of the server that delivered the email is listed in the SPF record.

  • Match (Pass): If the IP is on the list, the SPF check passes. The email is deemed legitimate.
  • No Match (Fail/SoftFail): If the IP is not on the list, the SPF check fails. The receiving server flags the email as potentially spoofed.

Constructing an SPF Record

A typical SPF record looks like this: v=spf1 ip4:192.168.0.1 include:_spf.google.com ~all

  • v=spf1: Identifies the record as an SPF version 1 record.
  • ip4:192.168.0.1: Authorizes this specific IP address to send mail.
  • include:_spf.google.com: Authorizes all servers listed in Google Workspace's SPF record to send mail on your behalf (crucial if you use cloud email providers).
  • ~all: The enforcement mechanism. ~all is a "SoftFail" (accept the mail but mark it as suspicious), -all is a "HardFail" (reject the mail outright), and ?all is neutral (no policy).

The Limitation of SPF: SPF only checks the Envelope Sender. It does not check the Header Sender (the address the user actually sees). Therefore, an attacker can still spoof the visible From: address, and as long as they use their own domain for the Envelope Sender (which has a valid SPF record), the email will pass SPF. This is why SPF alone is insufficient.

2. DomainKeys Identified Mail (DKIM)

While SPF verifies the server sending the email, DKIM verifies the content of the email and ensures it hasn't been tampered with in transit. It achieves this using public-key cryptography.

How DKIM Works

  1. Signing the Email: When an authorized mail server (like your Exchange server or Google Workspace) sends an email, it uses a private cryptographic key to generate a digital signature. This signature is based on the content of the email body and specific headers (like the From: and Subject: lines). This signature is added to the email as a hidden DKIM header.
  2. Publishing the Public Key: The domain owner publishes the corresponding public key as a TXT record in their DNS settings.
  3. Verifying the Signature: When the receiving server gets the email, it looks up the public key in your DNS. It uses this public key to decrypt and verify the DKIM signature.

If the signature is valid, it proves two things mathematically:

  • The email was genuinely sent by a server holding the private key for that domain (Authentication).
  • The content of the email (and the protected headers) was not altered in transit (Integrity).

The Limitation of DKIM: DKIM does not prevent an attacker from sending an email without a signature, nor does it tell the receiving server what to do if an email fails the signature check. Furthermore, like SPF, DKIM does not inherently force an alignment between the domain that signed the email and the visible From: address.

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

DMARC is the policy layer that brings SPF and DKIM together to provide comprehensive protection against spoofing. It addresses the critical limitations of both protocols.

The Power of DMARC Alignment

DMARC introduces the concept of Alignment. For an email to pass DMARC, it must pass either SPF or DKIM, AND the domain validated by that protocol must match (align with) the visible Header From: address.

If an attacker tries to spoof the Header From: to be yourcompany.com:

  • SPF Alignment Failure: They will use their own domain for the Envelope Sender to pass SPF. However, DMARC will see that the Envelope Sender domain does not match yourcompany.com, resulting in an SPF alignment failure.
  • DKIM Alignment Failure: They cannot generate a valid DKIM signature for yourcompany.com because they don't have your private key. If they sign it with their own domain's key, DMARC will see the domains don't match, resulting in a DKIM alignment failure.

Because both alignment checks fail, the email fails DMARC.

DMARC Policies and Reporting

DMARC is implemented via a DNS TXT record. Crucially, this record tells receiving servers exactly what to do with emails that fail the DMARC check.

A typical DMARC record: v=DMARC1; p=reject; rua=mailto:[email protected];

  • p=none: Monitor mode. The receiver does nothing to the email, but sends reports. (Used for initial deployment).
  • p=quarantine: Send failing emails to the recipient's spam/junk folder.
  • p=reject: The ultimate goal. Instructs the receiving server to outright delete or bounce the email before it ever reaches the user's inbox.

The rua tag instructs receiving servers to send aggregate XML reports back to you. These reports provide invaluable visibility, showing you every IP address globally that is sending email on behalf of your domain, allowing you to identify misconfigured internal servers or active spoofing campaigns.

Best Practices for Implementation

Implementing these protocols, especially DMARC, must be done methodically to avoid blocking legitimate business emails.

  1. Inventory and Configure (SPF & DKIM): First, audit all services that send email on behalf of your domain (Marketing platforms like Mailchimp, CRM systems like Salesforce, HR portals). Ensure every single one of them is correctly included in your SPF record and configured to sign emails with DKIM.
  2. Start with Monitor Mode (p=none): Publish a DMARC record with p=none. This will not affect mail delivery. Collect the DMARC reports (using a DMARC analysis tool) for several weeks.
  3. Analyze and Remediate: Review the reports to identify legitimate services that are failing DMARC (usually due to missing DKIM signatures or SPF misconfigurations). Fix these issues.
  4. Gradual Enforcement (p=quarantine -> p=reject): Once you are confident that all legitimate mail is passing DMARC, upgrade your policy to p=quarantine. Monitor for a few more weeks. Finally, enforce p=reject to completely neutralize domain spoofing attacks.
Key Takeaways

Relying on users to spot sophisticated phishing emails is a failing strategy. Organizations must implement technical controls at the infrastructure level to protect their domain reputation and secure their users. SPF, DKIM, and DMARC are not optional enhancements; they are fundamental requirements for modern email security. By authenticating the sending servers with SPF, ensuring cryptographic integrity with DKIM, and enforcing strict alignment and rejection policies with DMARC, organizations can effectively eliminate direct domain spoofing, significantly reducing the success rate of BEC and phishing campaigns targeting their employees and customers.

Ready to test your knowledge? Take the Email Authentication MCQ Quiz on HackCert today!

Related articles

back to all articles