SPF, DKIM and DMARC Explained: Stop Email Spoofing
December 5, 2026 · 11 min read

SPF, DKIM and DMARC are three DNS-based standards that prove an email really comes from the domain it claims, and tell receiving mail servers what to do when it does not. Without them, anyone can send email that appears to come from ceo@yourcompany.com, because the original email protocol has no built-in way to check the sender. With all three in place and DMARC enforced, spoofed messages are rejected or sent to spam, and your genuine emails are more likely to reach the inbox.
Email providers now insist on it. Google and Yahoo began enforcing authentication rules for bulk senders in February 2024, Microsoft followed for Outlook.com in May 2025, and from November 2025 Gmail moved to rejecting non-compliant messages outright. Adoption is growing but incomplete: EasyDMARC's 2026 report found valid DMARC records on 52.1% of the top 1.8 million domains, but only 22.9% used an enforcing policy. This guide explains how each standard works, shows example records and a test script, and gives a safe rollout plan.
How Email Spoofing Works
Every email has two sender addresses. The envelope sender (MAIL FROM, or Return-Path) is used by mail servers for delivery and bounces. The header From is what people see in their inbox. Neither was originally verified, so a criminal can put any domain in either. That is how the fake supplier invoices and "urgent request from the CEO" emails in our phishing email examples reach their targets.
| Standard | Question it answers | Where it lives |
|---|---|---|
| SPF | Is this server allowed to send mail for the envelope domain? | A TXT record on your domain |
| DKIM | Was this message signed by the domain, and is it unchanged? | A public key in a TXT record at selector._domainkey |
| DMARC | Does a passing SPF or DKIM result match the visible From domain, and what should happen if not? | A TXT record at _dmarc.yourdomain |
SPF: Which Servers May Send Your Email
Sender Policy Framework (RFC 7208) lists the servers and services allowed to send mail for your domain. A record such as v=spf1 include:_spf.google.com include:sendgrid.net -all says: Google Workspace and SendGrid may send for us, and everything else should fail.
- Qualifiers:
-allmeans fail anything not listed,~allmeans soft fail. Never use+all, which authorises the whole internet. - The 10-lookup limit: each
include,a,mx,existsorredirectcosts a DNS lookup, including those inside included records. More than ten causes a permanent error, and SPF fails for everyone. - One record only: two SPF records on the same domain also cause an error. Merge them.
- Weakness: SPF checks the envelope sender, not the From address people see, and it breaks when mail is forwarded. That is why it is not enough on its own.
DKIM: A Tamper-Proof Signature
DomainKeys Identified Mail (RFC 6376) adds a digital signature to each message. Your email service signs selected headers and the body with a private key, and publishes the matching public key in DNS under a selector, such as google._domainkey.example.com. Receivers fetch the key and verify the signature, which proves the message came from a holder of the key and was not altered in transit.
- Use 2048-bit RSA keys where your provider supports them; Gmail rejects keys shorter than 1024 bits.
- Each sending service, such as your email platform, CRM or helpdesk, should sign with your domain, not its own.
- Rotate keys periodically by publishing a new selector, switching signing to it and removing the old key later.
- DKIM usually survives forwarding, which makes it the most reliable path to DMARC success.
Like other public-key signatures, DKIM relies on algorithms that future quantum computers threaten; our guide to post-quantum cryptography explains the timeline for moving away from them.
DMARC: Alignment, Policy and Reports
Domain-based Message Authentication, Reporting and Conformance (RFC 7489) ties everything to the From address people see. A message passes DMARC if SPF or DKIM passes and the domain it passed for aligns with the From domain. Relaxed alignment, the default, accepts subdomains of the same organisational domain; strict alignment requires an exact match.
The DMARC record then sets a policy for messages that fail:
p=none: monitor only; deliver as normal and send reports. The right first step, but it stops nothing.p=quarantine: treat failures as suspicious, usually by sending them to spam.p=reject: refuse failing messages at the door. The goal for every domain.
The rua tag sets an address for daily aggregate reports, which list every source sending mail as your domain and whether it passed. These reports are how you find forgotten senders before you enforce, and how you spot spoofing afterwards. The IETF has been updating the specification under the name DMARCbis, but the core tags shown here remain the foundation.
Example Records
Here are the three records for a domain that sends through Google Workspace and SendGrid:
; DNS records for example.com (zone-file style)
example.com. IN TXT "v=spf1 include:_spf.google.com include:sendgrid.net -all"
google._domainkey.example.com. IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA..."
_dmarc.example.com. IN TXT "v=DMARC1; p=quarantine; rua=mailto:dmarc-reports@example.com; adkim=r; aspf=r"
You can look up any domain's records from the terminal with dig; our guide to Linux commands covers the basics.
#!/usr/bin/env bash
# check-dns.sh: look up a domain's email authentication records
DOMAIN="${1:-example.com}"
SELECTOR="${2:-google}" # DKIM selector, shown as s= in a message's DKIM-Signature header
echo "SPF:"; dig +short TXT "$DOMAIN" | grep -i "v=spf1"
echo "DMARC:"; dig +short TXT "_dmarc.$DOMAIN"
echo "DKIM:"; dig +short TXT "$SELECTOR._domainkey.$DOMAIN"
Test Your Records and Alignment
This script lints SPF and DMARC records and shows why alignment matters. It is a teaching tool; for production, use your DMARC reporting service or an online checker as well.
// email-auth-check.mjs: lint SPF and DMARC records and test DMARC alignment
const LOOKUP_MECHANISMS = /^(?:[+~?-])?(include|a|mx|ptr|exists|redirect)\b/;
function checkSpf(record) {
const problems = [];
const terms = record.trim().split(/\s+/);
if (terms[0] !== "v=spf1") problems.push("must start with v=spf1");
const lookups = terms.filter((t) => LOOKUP_MECHANISMS.test(t)).length;
if (lookups > 10) problems.push(`${lookups} DNS lookups; the limit is 10 (nested includes count too)`);
const all = terms.find((t) => /^[+~?-]?all$/.test(t));
if (!all) problems.push("no 'all' mechanism at the end");
else if (all === "+all" || all === "all") problems.push("+all lets anyone send as you");
else if (all === "?all") problems.push("?all is neutral and gives no protection");
return { lookups, all, problems };
}
function checkDmarc(record) {
const tags = Object.fromEntries(record.split(";").map((t) => t.trim().split("=")).filter((kv) => kv.length === 2));
const problems = [];
if (tags.v !== "DMARC1") problems.push("must start with v=DMARC1");
if (!["none", "quarantine", "reject"].includes(tags.p)) problems.push("p= must be none, quarantine or reject");
if (tags.p === "none") problems.push("p=none only monitors; plan a move to quarantine, then reject");
if (!tags.rua) problems.push("no rua= address, so you will get no aggregate reports");
return { policy: tags.p, problems };
}
// Relaxed alignment: the authenticated domain must share the organisational domain of the From address.
// (Simplified: real code should use the Public Suffix List for domains such as example.co.uk.)
const orgDomain = (d) => d.toLowerCase().split(".").slice(-2).join(".");
function dmarcPasses({ headerFrom, spfPass, mailFromDomain, dkimPass, dkimDomain }) {
const fromDomain = headerFrom.split("@").pop();
const spfAligned = spfPass && orgDomain(mailFromDomain) === orgDomain(fromDomain);
const dkimAligned = dkimPass && orgDomain(dkimDomain) === orgDomain(fromDomain);
return { spfAligned, dkimAligned, dmarc: spfAligned || dkimAligned ? "pass" : "fail" };
}
console.log("SPF", JSON.stringify(checkSpf("v=spf1 include:_spf.google.com include:sendgrid.net -all")));
console.log("SPF", JSON.stringify(checkSpf("v=spf1 a mx include:a.example include:b.example include:c.example include:d.example include:e.example include:f.example include:g.example include:h.example include:i.example ~all")));
console.log("DMARC", JSON.stringify(checkDmarc("v=DMARC1; p=none")));
console.log("DMARC", JSON.stringify(checkDmarc("v=DMARC1; p=quarantine; rua=mailto:dmarc-reports@example.com; adkim=r; aspf=r")));
// A newsletter sent through an email platform that uses its own bounce domain:
console.log("newsletter", JSON.stringify(dmarcPasses({
headerFrom: "news@example.com", spfPass: true, mailFromDomain: "bounces.esp-mail.net",
dkimPass: true, dkimDomain: "example.com",
})));
// A spoofed message: SPF passes for the attacker's own domain, but nothing aligns with example.com
console.log("spoof", JSON.stringify(dmarcPasses({
headerFrom: "ceo@example.com", spfPass: true, mailFromDomain: "attacker.example",
dkimPass: false, dkimDomain: "",
})));
Running it prints:
SPF {"lookups":2,"all":"-all","problems":[]}
SPF {"lookups":11,"all":"~all","problems":["11 DNS lookups; the limit is 10 (nested includes count too)"]}
DMARC {"policy":"none","problems":["p=none only monitors; plan a move to quarantine, then reject","no rua= address, so you will get no aggregate reports"]}
DMARC {"policy":"quarantine","problems":[]}
newsletter {"spfAligned":false,"dkimAligned":true,"dmarc":"pass"}
spoof {"spfAligned":false,"dkimAligned":false,"dmarc":"fail"}
Look at the last two lines. The newsletter's SPF result is for the email platform's bounce domain, so SPF does not align, but DKIM signed with example.com aligns and DMARC passes. The spoofed message passes SPF for the attacker's own domain, which is easy to arrange, yet nothing aligns with example.com, so DMARC fails and an enforced policy blocks it. That is exactly the protection SPF alone cannot give.
Bulk Sender Rules in 2026
| Provider | Applies to | Key requirements | Enforcement |
|---|---|---|---|
| Gmail | All senders; stricter rules above 5,000 messages a day to personal accounts | SPF and DKIM, DMARC (at least p=none) with alignment, TLS, spam rate under 0.3%, one-click unsubscribe | Since February 2024; permanent rejections from November 2025 |
| Yahoo and AOL | Similar thresholds | SPF, DKIM, DMARC, low complaint rates, one-click unsubscribe | Since February 2024 |
| Outlook.com and Hotmail | Senders of more than 5,000 messages a day | SPF, DKIM and DMARC passing with alignment | Rejections since May 2025 |
One-click unsubscribe uses the headers defined in RFC 8058. Google's own email sender guidelines are the definitive reference, and they apply to personal Gmail addresses rather than Google Workspace recipients. Even if you send far fewer messages, meeting these rules improves deliverability and protects your brand.
A Safe Rollout Plan
- Inventory every sender: office email, marketing platform, CRM, invoicing, helpdesk, website contact forms and any servers that send alerts.
- Publish one SPF record that includes them all and stays under ten lookups. Use subdomains such as
mail.example.comfor some services if you run out. - Turn on DKIM in each service, signing with your domain.
- Publish DMARC with
p=noneand aruaaddress, ideally handled by a reporting tool that turns the XML into readable dashboards. - Read the reports for two to four weeks, fixing every legitimate source that fails.
- Move to
p=quarantine, then top=rejectonce the reports are clean. - Protect unused domains with
v=spf1 -allandv=DMARC1; p=reject, because attackers love parked domains.
With DMARC at enforcement you can also add BIMI, which shows your verified logo next to your messages in supporting inboxes. Large companies have largely got there: EasyDMARC found 95% of the Fortune 500 with valid DMARC records and more than 80% at enforcement, while many smaller businesses remain stuck at p=none.
Reading DMARC Reports
Aggregate reports arrive as compressed XML files, usually once a day from each large mailbox provider. Each one lists the IP addresses that sent mail using your domain, how many messages each sent, and whether SPF, DKIM and DMARC passed. In practice you will see three groups of sources:
- Your known services passing: the goal state.
- Your known services failing: usually a missing DKIM set-up or an SPF include. Fix these before tightening the policy.
- Unknown sources failing: often spoofing attempts, sometimes a forgotten tool someone in marketing or sales signed up for. Investigate before you dismiss them.
Reporting services turn the XML into charts, alert you when a new source appears and help you decide when it is safe to move to the next policy. Keep reading the reports after you reach p=reject, because new tools and acquisitions add senders over time, and a sudden rise in failures can be an early warning of an impersonation campaign against your customers.
Common Mistakes
- Staying at
p=noneforever. It gives visibility but no protection. - Too many SPF lookups after adding one service too many.
- Services sending with their own domain instead of yours, so DKIM never aligns.
- Forgetting subdomains: set
sp=or publish records for subdomains that send mail. - Nobody reading the reports, so failures from a new tool go unnoticed until customers complain.
Email authentication is one layer. Combine it with staff awareness and phishing-resistant sign-in, as described in our cybersecurity guide for small businesses.
Frequently Asked Questions
What is DMARC in simple terms?
DMARC is a DNS record that tells receiving mail servers how to check that email claiming to be from your domain is genuine, what to do with messages that fail, and where to send reports.
Do I need SPF, DKIM and DMARC?
Yes. SPF and DKIM provide the authentication, and DMARC links them to the visible From address and sets the policy. Major email providers now expect all three from bulk senders.
What DMARC policy should I use?
Start with p=none and reporting, fix every legitimate sender, then move to p=quarantine and finally p=reject.
Why is my email failing DMARC?
Usually because a service sends mail for your domain without aligned DKIM signing or SPF authorisation, or because the SPF record exceeds ten DNS lookups. Your DMARC reports show which source is failing.
Does DMARC stop all phishing?
No. It stops attackers from spoofing your exact domain, but not look-alike domains or messages from hacked mailboxes. Training and phishing-resistant sign-in are still needed.
Is DMARC free?
Publishing SPF, DKIM and DMARC records is free. Many organisations pay for a reporting service to make sense of the reports, but free tiers exist for small domains.
Get Your Email Authentication Right
We audit your sending services, publish correct SPF, DKIM and DMARC records and take your domain to enforcement without breaking legitimate email. Contact our team to stop email spoofing.