Skip to content

Guide · Send and Hub

SPF, DKIM and DMARC: a practical guide with real record examples

Read and write SPF, DKIM and DMARC records with confidence: syntax, the 10-lookup limit, key rotation, moving DMARC from none to reject, and reading aggregate reports.

The Nexbit teamUpdated 9 min read

SPF, DKIM and DMARC are three DNS records that together answer one question for every receiving mail server: did this message really come from the domain in its From address? Get them right and your mail is trusted; get them wrong and it is filtered, quarantined or rejected. This guide explains each record with examples you can adapt, then shows how they work together.

All examples use acme.example. Replace it with your own domain.

How the three fit together

  • SPF checks the server that delivered the message against a list you publish.
  • DKIM checks a signature on the message against a public key you publish.
  • DMARC checks that at least one of them passed for the same domain the reader sees in the From address, and tells the receiver what to do if not.

That last point, called alignment, is what makes DMARC useful. Without it, a spammer could pass SPF for their own domain while showing your domain in the From line.

SPF

The standard is RFC 7208. SPF is a single TXT record on the domain that appears in the message's envelope sender (the return path, where bounces go), which is not always the same as the visible From address.

Syntax

acme.example.  TXT  "v=spf1 include:_spf.mailhost.example include:spf.sendhost.example ip4:203.0.113.25 ~all"

Reading left to right:

  • v=spf1 starts every SPF record.
  • include: imports another domain's SPF record. This is how you authorise an email provider.
  • ip4: and ip6: authorise specific addresses or ranges.
  • a and mx authorise the addresses your domain's A or MX records point to.
  • The final all says what to do with everything else: -all (fail), ~all (soft fail, accept but mark as suspicious) or ?all (neutral).

Start with ~all while you find every service that sends as you, then consider -all. With DMARC in place, receivers rely on the DMARC policy more than on the difference between -all and ~all.

The 10-lookup limit

To protect receivers, SPF allows at most 10 DNS lookups while evaluating a record (RFC 7208 section 4.6.4). Each include, a, mx, ptr, exists and redirect counts, including those inside included records. ip4, ip6 and all do not count. Go over the limit and the result is a permerror, which most receivers treat as a failure.

A typical company quickly collects includes: the mail provider, a marketing tool, a help desk, an invoicing system. Each of those may include others. The email DNS checker counts the lookups for you.

To get back under 10:

  1. Remove services you no longer use.
  2. Move product and marketing mail to their own subdomains (for example mail.acme.example and news.acme.example). Each subdomain has its own SPF record and its own budget of 10.
  3. Avoid ptr entirely and avoid a and mx unless you really send from those hosts.

Common SPF mistakes

  • Two records. v=spf1 must appear in exactly one TXT record per name. Two records make SPF fail with a permerror. Merge them.
  • Quoting. Some DNS panels add quotes; others need you to add them. A record that ends up as "\"v=spf1 ...\"" is broken.
  • Long records. A single TXT string is limited to 255 characters; longer records must be split into several strings in the same record. Most panels do this for you.

DKIM

The standard is RFC 6376. The sending server signs selected headers and the body with a private key and adds a DKIM-Signature header. The receiver fetches the public key from DNS and checks the signature.

Where the key lives

The public key is published under a selector you or your provider choose, under _domainkey:

nb202611._domainkey.acme.example.  TXT  "v=DKIM1; k=rsa; p=MIIBIjANBgkqh...IDAQAB"

Many providers ask for a CNAME instead, pointing at a record they host:

nb202611._domainkey.acme.example.  CNAME  nb202611._domainkey.acme-example.dkim.mailhost.example.

The CNAME form lets the provider rotate the key without you editing DNS.

Key types and sizes

  • RSA 2048-bit is the widely supported choice. Keys of 1024 bits still work but are considered weak; avoid them for new setups.
  • Ed25519 (RFC 8463) is newer and shorter. Not every receiver checks it yet, so it is used alongside an RSA signature, never alone.

Rotating keys

Rotate DKIM keys periodically, and immediately if a private key may have been exposed. Rotation without losing mail looks like this:

  1. Publish the new key under a new selector (for example nb202705).
  2. Wait for DNS to spread, then switch signing to the new selector.
  3. Keep the old selector published for a week or two, so messages signed just before the switch can still be verified.
  4. Remove the old record.

Using dated selectors makes it obvious which key is current.

DMARC

The standard is RFC 7489. DMARC is a TXT record at _dmarc on the domain in the From address.

_dmarc.acme.example.  TXT  "v=DMARC1; p=quarantine; rua=mailto:[email protected]; adkim=r; aspf=r; pct=100"

Tags

TagMeaningTypical value
vVersion; must come first.DMARC1
pPolicy for the domain: do nothing, quarantine (spam folder) or reject.none, then quarantine, then reject
spPolicy for subdomains, if different from p.Usually omitted (inherits p)
ruaWhere to send daily aggregate reports.mailto:[email protected]
rufWhere to send failure samples. Few receivers send them.Usually omitted
adkim, aspfAlignment mode: relaxed (r, subdomains count) or strict (s, exact match).r
pctPercentage of failing mail the policy applies to.100 (lower it only while ramping up)

Alignment, with an example

A message shows From: Acme <[email protected]>.

  • DKIM signed with d=mail.acme.example: aligned (strict and relaxed).
  • DKIM signed with d=acme.example: aligned in relaxed mode only.
  • DKIM signed with d=mailhost.example (the provider's own domain): not aligned. DKIM passes, but it does not count for DMARC.
  • Return path [email protected] with SPF passing: SPF aligned.
  • Return path on the provider's domain: SPF passes for the provider but is not aligned.

DMARC passes when either aligned DKIM or aligned SPF passes. Aligned DKIM is the more robust of the two, because SPF breaks when mail is forwarded.

Moving from none to quarantine to reject

  1. Publish p=none with rua. Nothing changes for delivery; you start getting reports.
  2. Read two to four weeks of reports. List every source sending as your domain. Fix legitimate ones (add them to SPF, turn on DKIM with your domain) and note the ones that are not you.
  3. Move to p=quarantine. Optionally use pct=25, then 50, then 100 over a few weeks.
  4. Move to p=reject once a few weeks at full quarantine show no legitimate mail failing.

Keep reading reports after you reach reject. A new marketing tool added by another team will show up there first.

Reading aggregate reports

Aggregate reports are XML files, usually compressed, sent daily by each receiver that saw your mail. Each one lists, per sending IP address: how many messages, the SPF and DKIM results, whether they aligned, and what the receiver did. You do not need to read the XML by hand. Look for:

  • Sources you do not recognise with high volumes: possible spoofing, or a forgotten service.
  • Your own services failing alignment: usually DKIM signed with the provider's domain instead of yours, or a return path on the provider's domain.
  • Forwarders: mail you sent that a mailing list or forwarding service passed on. SPF fails for these; aligned DKIM usually survives.

Use a dedicated mailbox for rua so reports do not clutter anyone's inbox. If the reporting address is on a different domain from the one being reported on, that domain has to publish a record authorising it (RFC 7489 section 7.1).

Two more records worth adding

  • MTA-STS (RFC 8461) and TLS reporting (RFC 8460) tell other servers to deliver mail to you only over verified encrypted connections, and to report problems.
  • BIMI lets some mailbox providers show your logo next to authenticated mail. It requires DMARC at quarantine or reject first.

A complete example

For a company that uses one provider for staff mail and another for product email on a subdomain:

; Staff mail
acme.example.                    MX     10 mx.mailhost.example.
acme.example.                    TXT    "v=spf1 include:_spf.mailhost.example ~all"
nb202611._domainkey.acme.example. CNAME  nb202611._domainkey.acme-example.dkim.mailhost.example.
_dmarc.acme.example.             TXT    "v=DMARC1; p=quarantine; rua=mailto:[email protected]"

; Product email on its own subdomain
mail.acme.example.               TXT    "v=spf1 include:spf.sendhost.example ~all"
s1._domainkey.mail.acme.example.  CNAME  s1._domainkey.sendhost.example.
bounces.mail.acme.example.       CNAME  bounces.sendhost.example.

The subdomain inherits the parent's DMARC policy unless you publish a separate _dmarc.mail.acme.example, or set sp= on the parent.

Questions we hear often

Do I need all three? Yes. Large mailbox providers expect SPF or DKIM on all mail, and both plus DMARC from domains that send in volume. Each covers a gap the others leave: SPF breaks on forwarding, DKIM alone says nothing about policy, and DMARC needs at least one of the other two to pass.

Does DMARC p=reject stop all spoofing of my brand? It stops exact-domain spoofing at receivers that check DMARC, which includes the large providers. It does not stop look-alike domains (acme-example.com) or display-name tricks ("Acme Support" from a free mailbox). Those need user awareness and, for look-alike domains, registering the obvious variants yourself.

My website sends mail through the web server. Is that a problem? Often, yes. Mail from a shared web server is rarely DKIM-signed with your domain and its IP address is shared with many other sites. Send website mail through your email provider's SMTP relay or a sending API instead, with your domain's DKIM.

How often should I check these records? Look after any change to your providers, and run a check every few months. Records get deleted during website rebuilds and registrar moves more often than anyone expects; a monitoring service or your provider's admin console can warn you when that happens.

What TTL should I use? The default of an hour is fine for these records. Lower it to five minutes a day before a planned change, so mistakes can be corrected quickly, and raise it again afterwards.

Check your own domain

Run the email DNS checker to see your SPF lookup count, DMARC policy and DKIM selectors in plain words, then build an updated DMARC record with the DMARC record builder.