Home / Guides / SPF, DKIM and DMARC explained: how to stop email spoofing
SPF, DKIM and DMARC explained: how to stop email spoofing
Email was designed without a way to prove who sent a message. The “From” address is just text, so anyone can type your domain there. Three DNS-based standards close that gap: SPF, DKIM and DMARC. Used together, they let receiving servers check whether a message really comes from your domain, and tell them what to do when it does not.
This guide explains each one in plain language and ends with a safe rollout plan.
The problem: anyone can forge the From address
When you send a letter, you can write any return address on the envelope. Email works the same way. An attacker can send a message that shows [email protected] in the From line without ever having access to your mail server. This is called spoofing, and it is the basis of many phishing and invoice-fraud attacks.
SPF, DKIM and DMARC do not hide your address. They give receivers evidence to decide whether a message is genuine.
SPF: which servers may send for your domain
Sender Policy Framework (SPF) is a list of the servers allowed to send email for your domain. You publish it as a TXT record at the root of your domain. For example:
v=spf1 include:_spf.google.com include:sendgrid.net ~all
When a message arrives, the receiving server looks at the domain in the envelope sender (also called the Return-Path or MAIL FROM address) and checks that the connecting server is on that domain’s list.
What the ending means:
-all(hard fail): servers not on the list must be treated as unauthorised.~all(soft fail): servers not on the list are suspicious. This is the most common setting and works well with DMARC.?all(neutral): no opinion. This gives you no protection.+all: allows everyone. Never use it.
Things to know about SPF:
- One record only. A domain must publish exactly one SPF record. Two records cause a permanent error, so merge them.
- 10 DNS lookups maximum. Every
include,a,mx,existsandredirectcounts, including those nested inside other includes. Going over the limit makes SPF fail. Adding many services is how this happens. - It checks the envelope, not the visible From. On its own, SPF does not stop someone from showing your address in the From line while using their own envelope domain. DMARC fixes that.
- It breaks on forwarding. When a message is forwarded, the forwarding server is not on your list.
DKIM: a signature that proves the message was not altered
DomainKeys Identified Mail (DKIM) adds a cryptographic signature to each outgoing message. The sending server signs selected headers and the body with a private key. The matching public key is published in DNS, so anyone can verify the signature.
The public key lives at a name made from a selector you choose, in this form:
selector1._domainkey.example.com
A DKIM record looks like this:
v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A...
Why DKIM matters:
- It proves the message was signed by someone who controls the domain’s key.
- It detects tampering: if the signed parts change in transit, verification fails.
- It usually survives forwarding, because the signature travels with the message.
Practical advice: use 2048-bit keys, because 1024-bit keys are considered weak. Your email provider usually generates the key and tells you which selector and record to publish. Google Workspace commonly uses google, and Microsoft 365 uses selector1 and selector2.
DMARC: tying it together and setting the policy
SPF and DKIM each check a domain, but neither is required to match the address people actually see. Domain-based Message Authentication, Reporting and Conformance (DMARC) fixes that and adds a policy.
DMARC passes when either SPF or DKIM passes and the domain it authenticated aligns with the visible From domain. It is published as a TXT record at _dmarc.yourdomain.com:
v=DMARC1; p=none; rua=mailto:[email protected];
The main tags:
| Tag | Meaning |
|---|---|
p |
Policy for your domain: none, quarantine or reject |
sp |
Policy for subdomains (optional) |
rua |
Address that receives daily aggregate reports |
pct |
Percentage of mail the policy applies to |
adkim, aspf |
Alignment mode: r (relaxed, default) or s (strict) |
The three policies tell receivers what to do with mail that fails DMARC:
- none: do nothing, just send reports. Safe for starting.
- quarantine: treat as suspicious, usually deliver to spam.
- reject: refuse the message.
The reports are what make DMARC useful. They show you every server that sends mail using your domain, including services you forgot about.
A safe rollout plan
Jumping straight to p=reject is the most common way to lose legitimate email. Go step by step:
- List every service that sends email for your domain: your mail provider, newsletter tool, CRM, help desk, billing system and website forms.
- Publish SPF including all of them, ending in
~all. Our SPF & DMARC generator builds the record for you. - Enable DKIM for each sending service and publish the keys it gives you.
- Publish DMARC with
p=noneand aruaaddress. Wait two to four weeks and read the reports. - Fix what fails. Add missing senders to SPF and turn on DKIM for them.
- Move to
p=quarantine, ideally starting with a lowpctsuch as 10, and raise it over time. - Move to
p=rejectonce the reports are clean.
Common mistakes
- Two SPF records. Merge them into one.
- Forgetting a sender, such as a billing system, so its mail starts failing.
- Exceeding 10 lookups with too many
includeentries. - Using
+allor?all, which protects nothing. - Never moving past
p=none. Monitoring alone does not block spoofing. - Sending reports to another domain without publishing the authorisation record that domain needs.
Domains that do not send email
If a domain never sends mail, say so. Publish v=spf1 -all and a DMARC policy of p=reject. Attackers like to spoof unused domains because nobody is watching them.
Why it matters even for small senders
Since 2024, Google and Yahoo require senders who send large volumes (more than 5,000 messages a day to their users) to authenticate with SPF and DKIM and to publish a DMARC policy. Even for low volumes, authenticated mail is far less likely to land in spam, and your domain is much harder to impersonate.
Check your setup
Use our Email Security Checker to see your SPF, DMARC, DKIM and MX records with clear warnings, including the SPF lookup count. The DNS Lookup tool shows the raw records. If you received a suspicious message, paste its headers into the Email Header Analyzer to see the SPF, DKIM and DMARC results the receiving server recorded.