SPF, DKIM and DMARC explained
SPF, DKIM and DMARC are three DNS-based standards that let a receiving mail server check whether a message that claims to come from your domain really does. SPF lists the servers allowed to send mail for the domain. DKIM adds a cryptographic signature to each message. DMARC tells receivers what to do when a message fails those checks and where to send reports about it.
Since February 2024, Gmail and Yahoo have required anyone who sends large volumes of mail to their users to set up all three. Google’s email sender guidelines list the details.
How SPF works
SPF (Sender Policy Framework, RFC 7208) is a TXT record on your domain that starts with v=spf1. When a server receives a message, it checks the IP address of the sending server against the SPF record of the envelope sender’s domain. The envelope sender is the Return-Path address, which can differ from the From address people see.
For example, v=spf1 include:_spf.example.net ip4:192.0.2.0/24 -all allows the servers listed in example.net’s SPF record and the 192.0.2.0/24 range, and fails everything else.
| Ending | Result for servers the record does not list |
|---|---|
-all | Fail. Receivers may reject the message. |
~all | Soft fail. Usually accepted but treated as suspicious. |
?all | Neutral. No statement either way. |
+all | Pass. Any server can send as you, so avoid it. |
Two limits cause most SPF failures. A domain may have only one SPF record, and evaluating it may take no more than 10 DNS lookups. Every include, a, mx, ptr, exists and redirect term counts, including those inside included records. Going over either limit makes SPF fail with a permanent error. The SPF checker counts the lookups for you.
How DKIM works
DKIM (DomainKeys Identified Mail, RFC 6376) signs each outgoing message with a private key held by your mail service. The matching public key is published as a TXT record at selector._domainkey.example.com, where the selector is a name chosen by the service. Receivers read the selector from the message’s DKIM-Signature header, fetch the key and verify the signature.
Because selectors can be any name, there is no way to list all of a domain’s DKIM keys from DNS. To check one, get the selector from a message header or your mail provider’s settings, then look up the TXT record at that name with the DNS lookup.
How DMARC works
DMARC (RFC 7489) is a TXT record at _dmarc.example.com. A message passes DMARC when SPF or DKIM passes and the domain that passed matches, or aligns with, the domain in the visible From address. This closes the gap SPF leaves open, because SPF on its own checks only the hidden envelope sender.
For example, v=DMARC1; p=quarantine; rua=mailto:dmarc-reports@example.com asks receivers to treat failing mail as suspicious and to send daily aggregate reports to that address.
| Tag | What it does |
|---|---|
v | Version. Must be DMARC1 and come first. |
p | Policy for failing mail: none, quarantine or reject. |
sp | Policy for subdomains, if different. |
rua | Address for daily aggregate reports. |
ruf | Address for per-message failure reports. |
pct | Percentage of failing mail the policy applies to. |
adkim, aspf | Alignment mode for DKIM and SPF: r (relaxed) or s (strict). |
How to roll out DMARC safely
- Publish SPF and DKIM for every service that sends mail as your domain, including newsletters, invoicing and support tools.
- Publish DMARC with
p=noneand a rua address, then read the reports for a few weeks to find senders you missed. - Move to
p=quarantineonce legitimate mail passes. - Move to
p=rejectwhen you are confident nothing legitimate still fails.
Check your records with the SPF checker and the DMARC checker, and confirm your mail servers with the MX lookup.
How to read the results on a real message
The quickest test is to send a message from your domain to a mailbox you control and look at its headers. In Gmail, open the message, choose Show original and read the summary at the top, which shows SPF, DKIM and DMARC with a pass or fail beside each.
Other mail programs show the same information in a header named Authentication-Results. It contains entries such as spf=pass, dkim=pass header.d=example.com and dmarc=pass. The header.d value is the domain that signed the message. If it shows your mail provider’s domain and not yours, DKIM is passing without alignment, and DMARC is relying on SPF alone.
Forwarding and mailing lists
Forwarded mail arrives from the forwarder’s server, which the original domain’s SPF record does not list, so SPF fails. A DKIM signature travels with the message and still verifies, provided nothing changed the content on the way.
Mailing lists often do change it. They add a footer or a tag in the subject line, and that breaks the signature. A standard called ARC (RFC 8617) lets each server that handles a message record the authentication results it saw, so the final receiver can take the original result into account. Large mailbox providers use it when deciding whether to trust forwarded mail.
DKIM keys: length and rotation
Use 2048-bit RSA keys for DKIM. Keys of 1024 bits are still accepted by many receivers but are considered weak. Replace keys from time to time. Rotation means publishing a new key under a new selector, switching the mail service to sign with it and removing the old record after a few days. Hosted mail services usually handle this for you.
Subdomains for bulk and automated mail
Many organizations send newsletters and automated notices from a subdomain, such as news.example.com, and keep the main domain for person-to-person mail. Each subdomain has its own SPF record and its own DKIM keys, so a problem with one stream of mail does not harm the reputation of the other.
DMARC’s relaxed alignment treats a subdomain and its parent as the same organization, so mail signed by news.example.com still aligns with a From address at example.com. A subdomain can also publish a DMARC record of its own when it needs a different policy.
Records that build on DMARC
- BIMI lets mailbox providers show your logo next to messages that pass DMARC. It requires a policy of quarantine or reject, and some providers, Gmail among them, also ask for a certificate that verifies the logo.
- MTA-STS (RFC 8461) lets a domain require that mail sent to it travels over an encrypted connection.
- TLS reporting (RFC 8460) asks senders to report failures to establish that encrypted connection.
None of these is needed for delivery. They are worth a look once SPF, DKIM and DMARC are in good order.
A troubleshooting checklist
- Run the SPF checker. Confirm there is one record, the lookup count is 10 or less and every sending service is included.
- Confirm that each sending service signs with DKIM using your domain and that its key is published.
- Run the DMARC checker. Confirm the record is at _dmarc and has a rua address.
- Send a test message and read the Authentication-Results header.
- Read the aggregate reports for sources you do not recognize.
Common questions
Do I need all three?
For reliable delivery, yes. SPF and DKIM show where a message came from, and DMARC ties them to the From address and tells receivers how to act. Large mailbox providers expect all three from bulk senders.
My domain doesn’t send email. What should I publish?
Publish v=spf1 -all so no server may send as the domain, and a DMARC record with p=reject. That stops others from using the unused domain for phishing.
Why does mail fail DMARC when SPF passes?
SPF may pass for the envelope sender’s domain while the From address uses a different domain. Without alignment, DMARC fails. Set up the sending service to use your domain in the envelope sender, or have it sign with DKIM using your domain.
How long do changes to these records take to work?
As long as the TTL of the old record. Receivers cache DNS answers like everyone else, so allow up to an hour for typical settings.
Does DKIM encrypt my email?
No. DKIM signs a message so that receivers can detect changes and confirm the signing domain. The content remains readable.
Can a domain have more than one DKIM key?
Yes. Each key is published under its own selector, and each service that sends mail for you normally has its own.
Will these records guarantee delivery to the inbox?
No. They prove the mail is really from your domain. Whether it reaches the inbox also depends on your sending reputation and on what the messages contain.