Guide
Set up SPF, DKIM and DMARC step by step
List every service that sends as your domain, publish SPF and DKIM for each one, then add DMARC and tighten it as the reports come in.
Updated
SPF, DKIM and DMARC are three DNS records that tell the rest of the world which mail really comes from your domain. Without them, anyone can send mail with your address in the From line, and mailbox providers are more likely to file your own mail as spam. Gmail and Yahoo now ask bulk senders for all three.
This guide takes you through the setup in the order that causes the fewest surprises. It takes an afternoon of work spread over a few weeks, because the last step waits for reports to arrive. You need access to your domain's DNS (at your registrar or DNS host) and to the admin pages of the services that send mail for you.
How the three records fit together
Each record answers a different question for the receiving mail server:
- SPF (Sender Policy Framework) lists the servers allowed to send mail for your domain. The receiver checks the address of the server that connected to it against that list.
- DKIM (DomainKeys Identified Mail) adds a signature to each message. The receiver fetches your public key from DNS and checks that the message wasn't changed on the way and was signed by someone holding your private key.
- DMARC (Domain-based Message Authentication, Reporting and Conformance) ties the two to the address people actually see in the From line, tells receivers what to do with mail that fails, and asks them to send you reports.
The link between them is called alignment. SPF checks the envelope sender (the return path), and DKIM checks the domain in the signature. Neither of those is the From address your reader sees. DMARC passes only when at least one of SPF or DKIM passes and its domain matches the From domain. That is why a service can pass SPF and still fail DMARC: it sends with its own return path, not yours.
Step 1: list everything that sends as your domain
Before you touch DNS, write down every service that sends mail with your domain in the From address. Most domains have more than their owners remember:
- your mailbox provider (Google Workspace, Microsoft 365, Fastmail, Proton and so on);
- newsletter and marketing tools;
- transactional mail from your website or app (password resets, receipts, notifications);
- help desk, CRM, invoicing and billing systems;
- forms on your website and the web host itself;
- printers, scanners and monitoring systems that send alerts.
If you are not sure, start with DMARC in monitoring mode (step 4 shows how) and read the first week of reports. They list every server that sent mail as your domain, including the ones nobody told you about.
Step 2: publish one SPF record
SPF lives in a single TXT record at the root of your domain. It starts with v=spf1, lists your senders,
and ends with an all rule that says what to do with everything else:
example.com. 3600 IN TXT "v=spf1 include:_spf.google.com include:mailgun.org -all"
Each sending service tells you what to add, usually an include: for their own SPF record. Collect them
in one record, because a domain may have only one: two SPF records make SPF fail for every message (see
more than one SPF record).
Keep these rules in mind:
- Stay within ten DNS lookups. Every
include,a,mx,existsandredirectcosts a lookup, and the includes inside includes count too. Past ten, receivers treat SPF as an error. The SPF checker counts them for you, and too many lookups explains how to get back under the limit. - End with
-allor~all.-all(fail) is the clear statement once you are sure the list is complete;~all(softfail) is a gentler start. Never use+all, which allows the whole internet. - Leave out
ptr. It is slow, unreliable and deprecated.
If you'd rather not write it by hand, the SPF builder puts the record together from
a list of providers and shows the lookup count as you go. A domain that never sends mail should still
publish v=spf1 -all, so nobody can use it for forgery.
Step 3: turn on DKIM for each sender
DKIM is set up per service, because each one signs with its own key. In each service's admin pages, look
for "DKIM", "domain authentication" or "custom sending domain". The service gives you one or more records
to publish, usually under a name like selector._domainkey.example.com:
google._domainkey.example.com. 3600 IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqh..."
s1._domainkey.example.com. 3600 IN CNAME s1.domainkey.u1234.wl.sendgrid.net.
Some services want a TXT record with the key itself; others want a CNAME pointing at a key they host, so they can change keys without asking you. Both work. After you publish the records, go back to the service and press its verify button, then send a test message.
A few things to check:
- Key length. Use 2048-bit RSA keys where the service offers them. 1024-bit keys still work but are considered weak; anything shorter should be replaced (weak DKIM key).
- The selector. The part before
._domainkeyis the selector. You need it to look the key up. The DKIM checker tries the selectors common providers use and lets you enter your own; selector not found helps when it can't find yours. - Long TXT records. A 2048-bit key is longer than 255 characters, so DNS hosts split it into several quoted strings. That is normal; receivers join them back together.
DKIM matters more than SPF for DMARC, because a DKIM signature survives forwarding, while SPF usually breaks when a message is forwarded through another server.
Step 4: add DMARC in monitoring mode
With SPF and DKIM in place, publish DMARC as a TXT record at _dmarc.example.com. Start with the policy
none, which changes nothing about delivery but asks receivers to send you reports:
_dmarc.example.com. 3600 IN TXT "v=DMARC1; p=none; rua=mailto:dmarc-reports@example.com"
The rua address receives aggregate reports: daily XML files from each large mailbox provider listing
which servers sent mail as your domain, how many messages, and whether SPF, DKIM and alignment passed. If
the address is on another domain, that domain has to publish a record allowing it to receive your
reports. The DMARC builder writes the record for each stage, and
no DMARC reports explains why reports matter even before you enforce.
Reports arrive as compressed XML and are hard to read by eye. A report service or a spreadsheet import helps. What you are looking for is simple: every source that sends real mail for you should pass with alignment, and everything that fails should be forgery or something you can switch off.
Step 5: fix what the reports show
Give the reports two to four weeks, so monthly mailings and rare systems show up. For each real sender that fails:
- If it fails SPF alignment, check whether the service lets you set a custom return-path (often called a bounce domain or MAIL FROM domain) on your own domain. If not, rely on DKIM for that service.
- If it fails DKIM, finish the DKIM setup from step 3 for that service.
- If you no longer use it, remove its include from SPF and switch it off.
You can check a single message too. Paste its full headers into the email header analyzer to see the SPF, DKIM and DMARC results the receiving server recorded, and which domains they used.
Step 6: move to quarantine, then reject
Once the reports show your real mail passing, tighten the policy in steps. First quarantine, which sends
failing mail to the spam folder. You can start with part of the traffic using pct:
_dmarc.example.com. 3600 IN TXT "v=DMARC1; p=quarantine; pct=25; rua=mailto:dmarc-reports@example.com"
Raise pct to 100 over a week or two while you watch the reports. When nothing real is being caught, move
to p=reject, which tells receivers to refuse failing mail outright. That is the goal: forged mail with
your domain no longer reaches anyone. Policy none walks through the same steps.
Two details worth setting at the end:
sp=sets the policy for subdomains. Without it, subdomains follow the main policy, which is usually what you want.adkim=sandaspf=sask for strict alignment (the exact domain, not a subdomain). The relaxed default is fine for most domains.
Check the whole setup
Run the email checker on your domain whenever you change something. It reads your MX, SPF, DKIM, DMARC, MTA-STS and BIMI records together, points at anything missing or broken, and links to a fix for each finding. If you protect inbound mail as well, the MTA-STS checker covers encryption between mail servers.
A few mistakes come up again and again:
- Two SPF records after adding a new service. Merge them into one.
- A DMARC record at the wrong name, such as at the root of the domain instead of
_dmarc. - Forgotten senders that start failing after you move to reject. The reports name them; fix them and keep the policy.
- Parked domains without records. Domains that never send mail should publish
v=spf1 -allandv=DMARC1; p=reject, so they can't be used to send forged mail.
Once you are at p=reject with everything passing, keep the reports coming and look at them now and
then, especially after you add a new tool that sends mail. Monitoring on DNS Super can watch the records
for you and send an alert when one changes or breaks.