SPF, DKIM and DMARC explained
What SPF, DKIM and DMARC records do, how to read the SPF and DMARC fields of an email result, and how to check and fix the records of your own domain.
SPF, DKIM and DMARC are three DNS records that let a domain say who may send email in its name, and what receivers should do with mail that fails the test. They matter twice for you: they tell you something about the domains of the addresses you check, and your own domain needs them for your email to reach inboxes.
Three records, three questions
| Record | Standard | Question it answers | Where it lives |
|---|---|---|---|
| SPF | RFC 7208 | Which servers may send mail for this domain? | A TXT record on the domain itself, starting with v=spf1 |
| DKIM | RFC 6376 | Was this message signed by the domain, and is it unchanged since? | A TXT record at <selector>._domainkey.<domain> |
| DMARC | RFC 7489 | What should a receiver do when a message fails, and where should it send reports? | A TXT record at _dmarc.<domain>, starting with v=DMARC1 |
SPF
An SPF record lists the servers allowed to send mail for the domain:
v=spf1 include:_spf.mailprovider.example ip4:192.0.2.10 -all
Read left to right: mail may come from the servers that _spf.mailprovider.example lists, or from 192.0.2.10; anything else fails (-all).
| Part | Meaning |
|---|---|
include: |
Also accept the servers listed in another domain's SPF record. This is how you authorize an email provider. |
ip4:, ip6: |
Accept these addresses or ranges. |
a, mx |
Accept the addresses of the domain's A or MX records. |
-all |
Fail everything not listed. The usual choice once the record is complete. |
~all |
Soft fail: accept but mark as suspicious. Useful while you are still finding all your senders. |
?all, +all |
Neutral, or accept everyone. +all lets anyone send as your domain: never use it. |
Three rules from RFC 7208 trip people up:
- One record only. A domain with two
v=spf1records gets a permanent error, as if it had none that works. Merge them. - At most 10 DNS lookups. Each
include,a,mx,ptr,existsandredirectcosts one, including those inside included records. Past 10, SPF fails. Remove senders you no longer use before you add new ones. - SPF checks the envelope sender, the address in the SMTP
MAIL FROMcommand, not theFromheader people see. That is why DMARC exists.
DKIM
DKIM signs each message with a private key. The receiver finds the public key in DNS and checks the signature. The DKIM-Signature header of a message names the domain (d=) and the selector (s=) to look up:
selector1._domainkey.example.com TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA..."
- Use 2048-bit RSA keys. RFC 8301 requires at least 1024 bits and recommends 2048. RFC 8463 defines Ed25519 keys as an alternative; if you use one, keep signing with an RSA key as well, so receivers that only verify RSA can still check your mail.
t=ymarks a key in testing mode: receivers should not treat failures as definitive.- An empty
p=means the key was revoked. - Rotate keys by publishing a new selector, switching your sender to it, then removing the old record.
The selector is chosen by whoever signs the mail, and DNS offers no way to list the selectors of a domain. That is why the email endpoint does not report DKIM: it would need a signed message to know where to look. To check a DKIM key, take the selector from a message's DKIM-Signature header and use the free DKIM checker.
DMARC
DMARC ties the two together. A message passes DMARC when SPF or DKIM passes for a domain that matches the domain in the visible From header. That match is called alignment. The record then tells receivers what to do with messages that fail, and where to send reports:
v=DMARC1; p=none; rua=mailto:dmarc-reports@example.com
| Tag | Meaning |
|---|---|
p= |
Policy for failing mail: none (only report), quarantine (send to spam) or reject. |
rua= |
Where to send daily aggregate reports. Without it, you never learn what fails. |
ruf= |
Where to send failure reports for individual messages. Many receivers do not send them. |
sp= |
Policy for subdomains, when it differs from p=. |
pct= |
Share of failing mail the policy applies to, from 0 to 100. |
adkim=, aspf= |
Alignment mode for DKIM and SPF: r (relaxed, the default: same organizational domain) or s (strict: exactly the same domain). |
A safe rollout:
- Publish
p=nonewith arua=address and read the reports for a few weeks. - Fix every legitimate sender that fails: add it to SPF, set up DKIM signing with your domain.
- Move to
p=quarantine, then top=rejectonce the reports are clean.
Mailbox providers increasingly expect this. Since February 2024, Google's and Yahoo's requirements for bulk senders include SPF and DKIM authentication and a published DMARC record.
Read the domain fields of an email result
Every POST /email result has a domain object:
| Field | Meaning |
|---|---|
domain.name |
The domain part of the address. |
domain.spf |
true when the domain publishes an SPF record, false when it does not, null when it was not checked, for example because the address failed the syntax check. |
domain.dmarc |
The same for a DMARC record at _dmarc.<domain>. |
These are presence checks: a published record can still be broken, and a domain without them can still receive mail. The domain fields come before the mailbox check, so fast mode returns them too:
import { Client } from '@qelka/sdk'
const client = new Client({ apiKey: process.env.API_KEY })
const result = await client.email.verify({ email: 'jane@example.com', mode: 'fast' })
console.log(result.domain)
{ name: 'example.com', spf: true, dmarc: true }
How to use them:
- Not as a reason to reject a signup. SPF and DMARC protect a domain's outgoing mail. A domain can receive mail perfectly well without either.
- As context about a company domain, for example when you review business leads: a domain that publishes both is one whose owner manages its email deliberately.
- To help your own customers. If you send email on behalf of your users' domains, missing records are worth flagging to them before deliverability suffers.
The fields do not by themselves change status. Whether they affect the quality score is documented on Email quality score.
Check your own domain
The free tools read the live records of any domain:
| Tool | What it shows |
|---|---|
| SPF checker | The record, its mechanisms, the number of DNS lookups it costs and the issues found |
| DMARC checker | The policy, the report addresses, the alignment modes and the issues found |
| DKIM checker | The key type and length, testing and revoked flags, for a selector you give it |
| MX lookup | The mail servers of the domain, including null MX records |
| DNS lookup | Any record type, when you need to see the raw data |
Common problems and fixes
| Problem | Fix |
|---|---|
| Two SPF records | Merge them into one record. |
| SPF over 10 DNS lookups | Remove the include of providers you no longer use, and replace a or mx with ip4 or ip6 ranges where you can: those cost no lookup. |
+all or ?all at the end of SPF |
Use -all, or ~all while you finish the inventory of your senders. |
DMARC without rua= |
Add a report address, or you will not see what fails. |
DMARC stuck at p=none |
Read the reports, fix the failing senders, then move to quarantine and reject. |
| DKIM key of 1024 bits | Publish a 2048-bit key under a new selector and switch your sender to it. |
| Mail from a provider fails DMARC | The provider signs with its own domain, or sends from its own envelope domain. Set up custom DKIM signing with your domain in the provider's settings. |