Skip to content

Email

SPF, DKIM and DMARC explained

What SPF, DKIM and DMARC actually do, example DNS records, the SPF 10-lookup limit, a safe DMARC rollout and the Gmail and Yahoo sender rules.

If your business email lands in spam, or someone sends phishing mail that looks like it came from your domain, the fix almost always starts with three DNS records: SPF, DKIM and DMARC. They are free to set up, they take about an hour, and since 2024 the biggest mailbox providers treat them as mandatory rather than optional. This guide explains what each one does, shows real example records, and walks through a safe rollout that won't break your own mail.

Why email needs authentication

The email protocol (SMTP) was designed in the 1980s with no way to prove who sent a message. Anyone can put [email protected] in the From line. SPF, DKIM and DMARC were added on top to answer two questions receiving servers care about:

  • Was this message sent by a server the domain owner approved? (SPF)
  • Was the message changed after it left, and does a domain vouch for it? (DKIM)

DMARC then ties those answers to the address people actually see in the From line and tells receivers what to do when a message fails.

SPF: which servers may send for your domain

Sender Policy Framework is a single TXT record on your domain that lists the servers and services allowed to send mail using it. The receiving server looks at the connecting IP address, fetches your SPF record and checks whether that IP is on the list.

example.com.  TXT  "v=spf1 mx include:_spf.google.com include:sendgrid.net ip4:203.0.113.25 -all"

Reading it left to right:

  • v=spf1 marks it as an SPF record.
  • mx allows the servers listed in your MX records.
  • include: pulls in another provider's list, such as your mailbox host or newsletter tool.
  • ip4: / ip6: allow a specific address or range, for example your web server that sends contact form mail.
  • -all says everything else should fail. ~all (softfail) is a gentler option while you are still finding all your senders.

Rules that trip people up

  • Only one SPF record per domain. Two TXT records starting with v=spf1 is an error, and receivers treat SPF as broken. Merge them into one.
  • SPF checks the envelope sender (the Return-Path), not the From address people see. That is why SPF alone doesn't stop spoofing, and why DMARC exists.
  • SPF breaks on forwarding. When a message is forwarded, it arrives from the forwarder's IP, which isn't in your record. DKIM survives forwarding, so you want both.

The 10 DNS lookup limit

To stop SPF being abused for denial of service, the standard (RFC 7208) caps evaluation at 10 DNS lookups. Every include, a, mx, exists, redirect and ptr counts, and so do the lookups inside each include. ip4, ip6 and all are free. Go over 10 and the result is permerror, which most receivers treat as a fail.

This is easy to hit. A typical business with Google Workspace or Microsoft 365, a CRM, a helpdesk and a newsletter tool can reach 10 without noticing, because a single include can use two or three lookups on its own. To stay under:

  1. Remove services you no longer use. Old includes are the most common cause.
  2. Replace a and mx with the actual ip4 addresses if they rarely change.
  3. Never use ptr; it is deprecated and slow.
  4. Send marketing and transactional mail from a subdomain (news.example.com, mail.example.com) with its own SPF record, so each record stays short.

There is also a limit of two "void" lookups (includes that return no record), so delete includes for domains that no longer exist.

DKIM: a signature that proves the message is genuine

DomainKeys Identified Mail adds a cryptographic signature to the headers of every message. The sending server signs with a private key, and you publish the matching public key in DNS. The receiver fetches the key and checks the signature. If the body or signed headers were altered in transit, the check fails.

DKIM keys live under a selector, which lets you have several keys at once (one per service, or old and new during a rotation):

selector1._domainkey.example.com.  TXT  "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu5...IDAQAB"

You don't write this key yourself. Each sending service (your mailbox host, your newsletter platform, your helpdesk) generates it and tells you the selector name and value, sometimes as a CNAME pointing to their own record. Some tips:

  • Use 2048-bit keys. 1024-bit keys still validate but are considered weak.
  • Long keys may need to be split into several quoted strings in one TXT record. Most DNS panels handle this automatically.
  • Set up DKIM for every service that sends as your domain, not just your main mailbox.
  • Rotate keys every 6 to 12 months by publishing a new selector, switching signing to it, then removing the old one after a week.

You can see the result in any received message. In Gmail, open the message, choose Show original and look for DKIM: 'PASS' with domain example.com.

DMARC: the policy that ties it together

Domain-based Message Authentication, Reporting and Conformance does two jobs. First, it requires alignment: SPF or DKIM must pass for the same domain that appears in the From line. A spammer can pass SPF for their own domain, but they can't make it align with yours. Second, it tells receivers what to do with mail that fails, and asks them to send you reports.

The record goes on the _dmarc subdomain:

_dmarc.example.com.  TXT  "v=DMARC1; p=none; rua=mailto:[email protected]; adkim=r; aspf=r"
TagMeaning
pPolicy for failing mail: none (monitor only), quarantine (send to spam) or reject (refuse it)
ruaWhere to send daily aggregate reports
pctPercentage of failing mail the policy applies to (default 100)
spPolicy for subdomains, if different from p
adkim / aspfAlignment mode: r (relaxed, subdomains match) or s (strict, exact match)

A message passes DMARC if either SPF or DKIM passes and aligns. That is why DKIM matters so much: it survives forwarding, so aligned DKIM keeps forwarded mail passing even when SPF fails.

Rolling out DMARC safely: none, quarantine, reject

Jumping straight to p=reject is the classic mistake. If your invoicing system or CRM sends as your domain and you forgot to set it up, its mail will start disappearing. Roll out in stages instead:

  1. Weeks 1 to 4: p=none. Nothing changes for delivery, but reports start arriving. Use them to find every service sending as your domain and fix SPF and DKIM for each one.
  2. Next 2 to 4 weeks: p=quarantine; pct=25. A quarter of failing mail goes to spam. Watch the reports and raise pct to 50, then 100, as long as no legitimate sources show up failing.
  3. Finally: p=reject. Spoofed mail is refused outright. Keep reading reports, because businesses add new tools all the time.
v=DMARC1; p=none; rua=mailto:[email protected]
v=DMARC1; p=quarantine; pct=25; rua=mailto:[email protected]
v=DMARC1; p=reject; rua=mailto:[email protected]

Domains that never send mail at all (parked domains, old brand names) can go straight to the strictest setup, since there's nothing to break: v=spf1 -all plus v=DMARC1; p=reject.

Reading rua reports

Aggregate reports are XML files, usually zipped, sent once a day by Google, Microsoft, Yahoo and others. Each one lists the IP addresses that sent mail claiming to be your domain, how many messages, and whether SPF and DKIM passed and aligned. They contain no message content.

The XML is hard to read by hand, so most people point rua at a free or paid DMARC report analyser that turns it into charts. When you look at the results, sort sources into three groups:

  • Your services, passing: good, nothing to do.
  • Your services, failing: add them to SPF or set up DKIM before you tighten the policy.
  • Unknown IPs failing: usually spoofing or spam. This is exactly what quarantine and reject will block.

Reports can be busy, so use a dedicated mailbox such as dmarc@ rather than your own inbox. If the address is on a different domain from the one being reported on, that domain must publish an authorisation record (example.com._report._dmarc.reportdomain.com with v=DMARC1), or receivers won't send to it. Report services set this up for you.

Gmail and Yahoo sender requirements

Since February 2024, Gmail and Yahoo enforce rules for everyone who sends to their users, with stricter rules for bulk senders (Google defines this as close to 5,000 or more messages a day to Gmail addresses). Microsoft introduced similar rules for Outlook.com in 2025.

RequirementAll sendersBulk senders
SPF or DKIMAt least oneBoth
DMARC recordRecommendedRequired (p=none is enough)
From domain aligned with SPF or DKIMRecommendedRequired
Valid reverse DNS (PTR) for sending IPsRequiredRequired
TLS for sendingRequiredRequired
Spam complaint rateBelow 0.3%, ideally below 0.1%Below 0.3%, ideally below 0.1%
One-click unsubscribe (RFC 8058)Not requiredRequired for marketing mail

Even if you only send a few hundred messages a day, meeting the bulk sender list is the simplest way to stay out of spam folders. Once you pass the threshold, Google treats you as a bulk sender permanently.

Testing your setup

Check your records from the command line first:

dig +short TXT example.com
dig +short TXT selector1._domainkey.example.com
dig +short TXT _dmarc.example.com

On Windows, use nslookup -type=TXT _dmarc.example.com. Then test real delivery:

  • Send to a Gmail address and use Show original to see SPF, DKIM and DMARC results for that exact message.
  • mail-tester.com gives you a throwaway address and scores a test message, including authentication and blocklist checks.
  • MXToolbox checks SPF syntax, counts your DNS lookups and looks up DKIM and DMARC records.
  • Google Postmaster Tools shows your domain's spam rate and authentication results at Gmail once you send enough volume.

DNS changes can take up to the record's TTL to spread, so wait a little before retesting.

Inbound protection is the other half

SPF, DKIM and DMARC protect your domain's reputation and stop others pretending to be you. They don't stop spam, phishing and malware aimed at your mailboxes from other domains. That's the job of an inbound filter. Zettako's email services include MXFilter filtering, which sits in front of your existing mail server once you point your MX records at it and blocks spam, phishing, viruses and malware before they reach your inbox. Pointing MX at a filter doesn't change your outgoing mail, but if your SPF record uses the mx mechanism, review it after the change so it still matches the servers that actually send for you.

Quick checklist

  1. List every service that sends as your domain.
  2. Publish one SPF record that covers them all and stays under 10 lookups.
  3. Turn on DKIM for each service, with 2048-bit keys.
  4. Publish DMARC at p=none with a rua address.
  5. Fix every legitimate source shown failing in the reports.
  6. Move to quarantine, then reject.
  7. Lock down domains that never send mail.

Keep spam out of your inbox

Authentication protects your domain. MXFilter filtering protects your mailboxes from spam, phishing and malware.

Starting at €6.99EUR/mo