Email Authentication: SPF, DKIM, and DMARC
Implement and validate Sender Policy Framework, DomainKeys Identified Mail, and DMARC policies that prevent domain spoofing and phishing.
Email Authentication: SPF, DKIM, and DMARC is a free Cloud & IT Cert Prep lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cloud & IT Cert Prep learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Email Spoofing Problem
The core SMTP protocol (designed in the 1970s) has no built-in sender authentication. Any mail server can claim to send email from any domain — a technique called email spoofing. Attackers exploit this to send phishing emails that appear to come from legitimate organizations (your bank, your CEO, a known vendor). Three DNS-based email authentication standards were developed to address this: SPF, DKIM, and DMARC. Each addresses a different aspect of the spoofing problem, and they work best when deployed together.
Sender Policy Framework (SPF)
SPF is a DNS TXT record that specifies which mail servers are authorized to send email on behalf of a domain. When a receiving mail server gets a message claiming to be from example.com, it looks up the SPF record for example.com and verifies that the sending server's IP address is listed. If the IP is not authorized, the message can be marked as spam or rejected. SPF checks the envelope From address (the SMTP MAIL FROM command), not the display From header visible to users.
# SPF DNS TXT record for example.com
# Authorize Google Workspace + SendGrid + company IP
example.com. TXT 'v=spf1 include:_spf.google.com include:sendgrid.net ip4:203.0.113.10 -all'
# Mechanism meanings:
# include: authorize another domain's SPF record
# ip4: authorize specific IPv4 address/range
# ip6: authorize specific IPv6 address
# -all FAIL (reject) mail from non-listed sources
# ~all SOFTFAIL (accept but mark as spam)
# ?all NEUTRAL (no policy stated)SPF Limitations
SPF has two significant limitations. First, forwarding breaks SPF: when email is forwarded, the forwarding server's IP is not in the original domain's SPF record, causing SPF to fail on legitimate forwarded mail. Second, SPF only authenticates the envelope From (invisible to users), not the From header visible in email clients. Attackers can still spoof the visible From header while using an SPF-passing envelope From — this is why SPF alone is insufficient. DKIM and DMARC address these gaps.
DomainKeys Identified Mail (DKIM)
DKIM adds a cryptographic signature to outgoing emails. The sending mail server uses a private key to sign specific email headers and the message body, adding a DKIM-Signature header. The public key is published as a DNS TXT record under a selector subdomain. Receiving servers retrieve the public key and verify the signature, confirming that the email was not tampered with in transit and that it originated from a server with access to the private key. Unlike SPF, DKIM signatures survive forwarding because they are carried in the email headers.
# DKIM DNS TXT record (selector: 'google')
google._domainkey.example.com. TXT \
'v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GN...'
# DKIM-Signature header in email:
DKIM-Signature: v=1; a=rsa-sha256; d=example.com;
s=google; h=from:to:subject:date;
bh=<body_hash>; b=<signature>
# Verification:
# 1. Extract 'b=' (signature)
# 2. Fetch public key at google._domainkey.example.com
# 3. Verify signature over 'h=' headers + body hashDKIM Selectors and Key Rotation
DKIM uses selectors to allow multiple simultaneous public keys for a domain — useful for running multiple mail services (Google Workspace + a marketing platform) or for key rotation without disruption. The selector name is included in the DKIM-Signature header so receiving servers know which DNS record to query. Organizations should rotate DKIM keys annually or when a key is suspected compromised. Key length: minimum 2048-bit RSA keys are recommended; 1024-bit keys are deprecated and breakable with modern compute.
DMARC: Domain-Based Message Authentication
DMARC (Domain-based Message Authentication, Reporting, and Conformance) builds on SPF and DKIM by adding: an alignment check (the domain in the visible From header must align with the SPF or DKIM authenticated domain) and a policy that tells receiving servers what to do when messages fail. DMARC policies are none (monitor only), quarantine (deliver to spam folder), or reject (do not deliver). DMARC also enables aggregate reports (RUA) and forensic reports (RUF) sent back to the domain owner for visibility into who is sending on your behalf.
# DMARC DNS TXT record
_dmarc.example.com. TXT \
'v=DMARC1; p=reject; sp=reject; \
pct=100; \
rua=mailto:dmarc-reports@example.com; \
ruf=mailto:forensic@example.com; \
adkim=s; aspf=s'
# p=reject : reject failing messages (strongest)
# pct=100 : apply to 100% of messages
# adkim=s : strict DKIM alignment
# aspf=s : strict SPF alignment
# rua= : aggregate report destinationDMARC Alignment
Alignment is what makes DMARC powerful against header spoofing. For SPF alignment, the domain in the SMTP envelope From must match the domain in the visible From header. For DKIM alignment, the signing domain (d= in DKIM-Signature) must match the From header domain. In strict mode, domains must match exactly. In relaxed mode, subdomains are acceptable. An email passes DMARC if it passes SPF OR DKIM with proper alignment — it does not need to pass both. The combination closes the loophole that SPF alone leaves open for visible header spoofing.
# DMARC alignment example
Envelope From: attacker@legit.com <- SPF may PASS for legit.com
From header : spoofed@example.com <- VISIBLE to user
# Without DMARC: SPF passes (envelope from legit.com)
# User sees spoofed@example.com and trusts it
# With DMARC on example.com:
# SPF alignment check: legit.com != example.com -> FAIL
# DKIM: attacker has no private key for example.com -> FAIL
# DMARC result: FAIL -> message rejected per policyDeploying DMARC in Stages
Organizations should deploy DMARC progressively to avoid disrupting legitimate email. Stage 1: Deploy SPF and DKIM for all mail streams. Stage 2: Publish p=none DMARC record with RUA reporting. Analyze reports (tools: DMARC Analyzer, dmarcian) to discover all legitimate sending sources over 2-4 weeks. Stage 3: Move to p=quarantine; pct=10, gradually increasing pct to 100%. Stage 4: Move to p=reject once all legitimate streams pass. Rushing to reject before discovering all mail streams causes legitimate email to be rejected.
# DMARC rollout stages
Stage 1: p=none; pct=100 (monitoring only)
Stage 2: p=quarantine; pct=10 (10% to spam)
Stage 3: p=quarantine; pct=100 (all to spam)
Stage 4: p=reject; pct=100 (block at MTA)
# Monitor RUA reports between each stage
# Look for legitimate sources failing alignment
# Common gotchas:
# - Marketing platforms sending as your domain
# - IT ticketing systems
# - Automated notification services
# - Third-party CRM toolsBIMI: Brand Indicators for Message Identification
BIMI is an emerging standard that builds on DMARC. When a domain has a DMARC policy of quarantine or reject, email clients (Gmail, Apple Mail) can display the brand's verified logo next to the sender's name in the inbox. BIMI requires a Verified Mark Certificate (VMC) from an approved issuer confirming trademark ownership. While BIMI is not yet on the Security+ exam, it represents the direction of email authentication — making verified senders visually distinguishable from spoofed ones at a glance.
SPF+DKIM+DMARC Working Together
The three standards form a complete email authentication system. SPF verifies the sending server is authorized by the domain owner. DKIM verifies message integrity and that the sending organization holds the private key. DMARC ties both to the visible From header, enforces policy on failures, and provides reporting. No single standard is sufficient: SPF alone cannot prevent visible header spoofing; DKIM alone does not mandate rejection of failures; DMARC alone without SPF or DKIM has nothing to check against. All three must be deployed together for full protection against domain spoofing.
# Email authentication check order
1. Receiving MTA receives message
2. SPF check: is sending IP authorized? (envelope From)
3. DKIM check: is signature valid? (using public key DNS)
4. DMARC check:
a. Did SPF pass with alignment? OR
b. Did DKIM pass with alignment?
-> If YES: PASS (deliver normally)
-> If NO: apply DMARC policy (none/quarantine/reject)
5. Reporting: send aggregate data to rua= addressExternal Email Banners
A practical defense-in-depth measure against phishing and BEC is adding an external email warning banner to every message that originates from outside the organization. This banner — typically inserted by the SEG — alerts employees that an email came from an external sender, even when the display name appears to be a colleague or executive. Banners are especially effective at flagging BEC attempts where the attacker uses a lookalike domain or display-name spoofing. The banner should be visually distinctive (colored header or footer) and should include instructions for reporting suspicious messages.
# Example external email banner (SEG inserts this)
# --- EXTERNAL EMAIL ---
# This message was sent from outside the organization.
# Do not click links or open attachments unless
# you expected this email and trust the sender.
# Report suspicious email: phishing@company.com
# ----------------------
# Proofpoint SEG: add disclaimer via content filter
# Match: Header 'X-MS-Exchange-Organization-SCL' absent
# Action: Prepend HTML banner to message bodyQuick Check
Test your understanding of CompTIA Security+ (SY0-701) concepts from this lesson.
Lesson Recap
In this lesson you learned: SPF uses DNS TXT records to authorize sending IPs but only checks the envelope From, not the visible header, DKIM adds cryptographic signatures that verify message integrity and survive forwarding, and DMARC ties SPF and DKIM to the visible From header with alignment checks and an enforceable policy (none/quarantine/reject) plus reporting. Next up we explore secure email gateways and anti-spam controls.
Frequently asked questions
Is the “Email Authentication: SPF, DKIM, and DMARC” lesson free?
Yes — the full text of “Email Authentication: SPF, DKIM, and DMARC” is free to read here on the web, and the Cloud & IT Cert Prep course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cloud & IT Cert Prep course, upgrade to CoddyKit PRO.
What will I learn in “Email Authentication: SPF, DKIM, and DMARC”?
Implement and validate Sender Policy Framework, DomainKeys Identified Mail, and DMARC policies that prevent domain spoofing and phishing. You practise Cloud & IT Cert Prep with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Cloud & IT Cert Prep?
No prior experience is required. Cloud & IT Cert Prep on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Email Authentication: SPF, DKIM, and DMARC” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Cloud & IT Cert Prep lesson?
Yes. Every Cloud & IT Cert Prep lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Email Authentication: SPF, DKIM, and DMARC
- Secure Email Gateways and Anti-Spam Controls
- Web Content Filtering and DNS Sinkholes
- SSL/TLS Inspection and Man-in-the-Browser Attacks