Introduction
Email authentication is essential to prevent domain spoofing, phishing, and spam folder rejection. Three DNS-based standards — SPF, DKIM, and DMARC — work together to verify that emails claiming to be from your domain are legitimate. Without these records, attackers can send forged emails on your behalf, and legitimate emails may land in recipients’ spam folders. This guide explains each standard and shows how to configure them on Cloudflare or your DNS provider.
SPF: Sender Policy Framework
SPF publishes a list of IP addresses authorized to send email for your domain. Recipient mail servers check the Return-Path domain against the SPF record.
SPF Record Format
A SPF record is a DNS TXT record:
example.com TXT "v=spf1 include:_spf.google.com include:spf.mailgun.org ~all"
| Mechanism | Meaning |
|---|---|
v=spf1 | SPF version identifier |
include: | Delegates authorization to another domain |
ip4:/ip6: | Authorizes specific IP ranges |
a | Authorizes the domain’s A record |
mx | Authorizes the domain’s MX servers |
all | Default action for non-matching senders |
Qualifiers
| Qualifier | Action |
|---|---|
+ | Pass (default) |
~ | SoftFail (marked but accepted) |
- | Fail (should be rejected) |
? | Neutral (no assertion) |
Use ~all during initial setup, then migrate to -all once verified.
DKIM: DomainKeys Identified Mail
DKIM attaches a cryptographic digital signature to each outgoing email. The receiving server retrieves the sender’s public key from DNS to verify that the email was not tampered with.
DKIM Record
A DKIM record is a DNS TXT record under a specific selector name:
default._domainkey.example.com TXT "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC..."
| Tag | Meaning |
|---|---|
v | Version (always DKIM1) |
k | Key type (rsa or ed25519) |
p | Base64-encoded public key |
Email services like Google Workspace, Mailgun, or SendGrid generate DKIM keys automatically. You only need to publish the public key as a DNS TXT record.
DMARC: Domain-based Message Authentication, Reporting & Conformance
DMARC defines a policy for how receivers should handle emails that fail SPF and/or DKIM checks. It also provides reporting to help you monitor authentication results.
DMARC Record Format
A DMARC record is a DNS TXT record:
_dmarc.example.com TXT "v=DMARC1; p=quarantine; rua=mailto:[email protected]; pct=100"
| Tag | Meaning | Common Values |
|---|---|---|
v | Version (always DMARC1) | DMARC1 |
p | Policy for unauthenticated emails | none, quarantine, reject |
pct | Percentage of emails subject to policy | 1–100 |
rua | Aggregate report email address | mailto: URI |
ruf | Forensic failure report address | mailto: URI |
sp | Subdomain policy (overrides p if set) | same as p |
DMARC Policy Levels
p=none— Monitor only, no action taken (use this first to validate)p=quarantine— Mark failures as spamp=reject— Reject failures outright (strictest)
How They Work Together
Sender sends email → Receiver checks SPF (is IP authorized?)
→ Receiver checks DKIM (is signature valid?)
→ Receiver checks DMARC policy
→ p=none: no action
→ p=quarantine: move to spam
→ p=reject: reject delivery
For an email to pass DMARC, it must pass either SPF (with alignment) or DKIM (with alignment). Alignment means the domain in the From header matches the domain used for SPF or DKIM.
Configuration on Cloudflare
- Add SPF record: Create a
TXTrecord for@with valuev=spf1 include:_spf.google.com ~all - Add DKIM record: Create a
TXTrecord fordefault._domainkeywith your provider’s public key - Add DMARC record: Create a
TXTrecord for_dmarcwith valuev=DMARC1; p=none; rua=mailto:[email protected] - Start with
p=none, review reports for a week, then escalate top=quarantineorp=reject
Checking Tools
- MXToolbox — Check SPF, DKIM, and DMARC records
- Google Admin Toolbox — Verify DMARC policy and reporting
- DMARC Analyzer — Parse and visualize DMARC aggregate reports
digcommand:dig TXT example.com dig TXT default._domainkey.example.com dig TXT _dmarc.example.com
Conclusion
SPF, DKIM, and DMARC form a layered email authentication strategy. SPF authorizes sending IPs, DKIM provides cryptographic integrity, and DMARC dictates the enforcement policy. Start with monitoring mode (p=none) to ensure legitimate mail authenticates correctly, review your DMARC reports, and then progressively enforce stricter policies. Properly configured, these records dramatically reduce spam classification and prevent domain spoofing.
