Caloogy Article
中文

Email Authentication: SPF, DKIM, and DMARC

Date
Mar 9, 2026
Series
Web Security
Reading
4 min
Topics
EmailSpfDkimDmarc

The one-sentence version

Email was born without any authentication: anyone could send an email with "From: [email protected]". Three DNS mechanisms were later added to address different issues: SPF specifies "which servers are allowed to send on my behalf," DKIM applies a digital signature to every email, and DMARC specifies "how to handle emails impersonating me" and requires sender domain alignment. Once all three are configured and the DMARC policy is tightened, phishing emails impersonating your domain will be sent directly to the spam folder or rejected. Combined with "anti-phishing codes" and "avoiding actionable links in emails," the probability of users being deceived by fake emails can be significantly reduced.

This article has three layers:

  1. Layer 1: The Intuition: Why email is so easy to spoof
  2. Layer 2: Real-World Use: BEC scams, 2024 Gmail and Yahoo new requirements, anti-phishing codes
  3. Layer 3: Principles and engineering key points: Detailed breakdown of the three DNS records, "alignment," and the transition from p=none to reject

Layer 1: The Intuition

1.1 The sender on the envelope can be anything

When sending a physical letter, you can write any sender address on the envelope, and the post office will not check it. Early email protocols (SMTP) worked the same way: the sender address was just a line of text that could be filled in arbitrarily.

1.2 Three patches

Mechanism Analogy Question it answers
SPF A company announces, "We only use these specific couriers to send mail" Is this email sent from an authorized server?
DKIM A company's official seal (digital signature) on every letter Was this email truly issued by this domain? Was it modified in transit?
DMARC A company tells all post offices: "If a fake letter doesn't meet the above rules, please throw it away" What to do if verification fails? Does the sender address match the verification result?

Layer 2: Real-World Use


Layer 3: Principles and Engineering

3.1 SPF

Add a TXT record in your DNS:

example.com.  TXT  "v=spf1 include:_spf.some-email-service.com -all"

The receiving server checks: Does the domain of the email's envelope sender (Return-Path) allow the sending server's IP to send mail? -all means all other servers are not allowed.

Limitations: SPF only checks the envelope sender, while users see the From: in their email client; the two can be different. Therefore, SPF alone cannot prevent impersonation and requires DMARC "alignment." Once expanded, an SPF record can have a maximum of 10 DNS lookups; having too many integrated sending services will exceed this limit.

3.2 DKIM

The sending server uses a private key to sign key email headers and the body, placing the signature in the DKIM-Signature header:

DKIM-Signature: v=1; a=rsa-sha256; d=example.com; s=sel1; h=from:to:subject:date; bh=...; b=...

The receiving server uses the s= (selector) and d= (domain) to look up the sel1._domainkey.example.com in DNS to verify the signature with the public key. The signature algorithm is typically RSA (see "RSA and Euler's Theorem"), but Ed25519 is also supported.

The advantage of DKIM is that it can survive forwarding: as long as the signed parts are not modified, the signature can still be verified after forwarding.

3.3 DMARC and "Alignment"

_dmarc.example.com.  TXT  "v=DMARC1; p=quarantine; adkim=r; aspf=r; rua=mailto:[email protected]"

The core rule of DMARC: At least one of SPF or DKIM must pass, and the domain used by the passing mechanism must be aligned with the From: domain seen by the user (r relaxed alignment allows subdomains, while s strict alignment requires an exact match).

Policy p= How the recipient handles fake mail
none Deliver as usual, only send you reports (used for monitoring)
quarantine Send to spam
reject Reject directly

rua= specifies the address for receiving aggregate reports. Major email providers will tell you every day: "How many emails were sent in your name, how many passed, and how many failed."

3.4 Steps for tightening security

  1. First, clearly list all channels sending mail on your behalf (marketing emails, transaction notifications, customer service systems, personal email);
  2. Configure SPF and DKIM for each channel;
  3. Use p=none for DMARC first to collect reports for a period of time to ensure all legitimate emails pass;
  4. Change to p=quarantine and observe further;
  5. Finally change to p=reject.

Skipping step 1 and tightening immediately most commonly results in your own legitimate emails (such as a forgotten system notification) being sent entirely to the spam folder.

3.5 What DMARC cannot control

These can only be mitigated through user education, anti-phishing codes, and "not putting actionable links in emails."


Summary

Mechanism In a nutshell
SPF Who can send on my behalf
DKIM Every email has my signature
DMARC How to handle fake mail, and sender must be aligned
Tightening route Inventory channels → none observe → quarantine → reject
Supplements Anti-phishing codes, no actionable links in emails, to deal with similar domains