SPF, DKIM and DMARC for a domain that sends mail from several services
In this article11 sections
Most small businesses do not send email from one place. Staff mail goes out through Google Workspace or Microsoft 365, the website sends order confirmations, a newsletter tool sends campaigns, a billing or CRM system sends invoices and reminders. Every one of those services sends mail “from” your domain, and every one of them has to be authorised or receiving servers will treat the message as suspect.
This is where email authentication goes wrong in practice. Not in the theory of SPF, DKIM and DMARC, but in the interaction between them when several senders are involved: two SPF records, too many lookups, a service that signs with the wrong domain, a DMARC policy switched on before anyone looked at the reports. This guide walks through the setup in the order that avoids those mistakes.
What each record does, in one paragraph each
SPF is a list, published in DNS, of the servers allowed to send mail for your domain. The receiving server checks the connecting address against that list.
DKIM is a signature. Your sending service adds a cryptographic signature to each message, and publishes the matching public key in DNS. The receiver checks that the message was signed by a key your domain published and was not changed on the way.
DMARC is the policy and the reporting. It says: “a message that claims to be from my domain must pass SPF or DKIM and the passing domain must match the visible From domain; if it does not, here is what to do, and please send me reports.” The matching requirement is called alignment, and it is the part people miss.
Step 1: Make a list of every sender
Before touching DNS, find out who sends mail for you. Do not guess. Sources:
- Ask each team which tools they use to email customers.
- Check your DNS for existing
include:entries in the current SPF record. Each one is a service somebody once set up. - Look at the From addresses on recent mail in your own mailbox: invoices, receipts, password resets, newsletters, calendar invitations, support-desk replies.
- Turn on DMARC reporting in monitoring mode (Step 5) and read who shows up. You will usually find one or two senders nobody remembered.
For each sender, write down: the service, the address it sends from, whether it can sign with DKIM for your own domain, and which hostname it uses for the return path (more on that below).
Step 2: One SPF record, and mind the lookup limit
A domain must have exactly one SPF record. Two records make SPF fail with a permanent error, which many receivers treat as no SPF at all. The classic mistake is adding a second v=spf1 … line when a new service asks you to “add this record”. Instead, merge: add the new service’s include: into the existing record.
A merged record looks like this:
example.com. TXT "v=spf1 include:_spf.google.com include:spf.mailprovider.example include:sendgrid.net ip4:203.0.113.10 -all"
Read it left to right: Google Workspace is allowed, the transactional provider is allowed, the newsletter service is allowed, one specific server address is allowed, and everything else is rejected (-all).
The ten-lookup limit. SPF allows at most ten DNS lookups while evaluating a record. Every include:, a, mx, exists and redirect counts, and so do the lookups inside each included record. Go over, and SPF fails with a permanent error. Services that nest several includes can use up the budget quickly.
Check your record’s lookup count with any SPF checker, or by following includes yourself:
dig +short TXT example.com | grep spf1
dig +short TXT _spf.google.com
If you are over the limit:
- Remove services you no longer use. This is the usual cure.
- Use
ip4:andip6:addresses for servers you control; they do not cost lookups. - Avoid
ptr. It is slow, discouraged and should not be used. - “Flattening” (replacing includes with the addresses they resolve to) works, but it silently goes wrong when the provider changes its addresses, unless something re-flattens automatically. Treat it as a last resort and know who maintains it.
-all or ~all? -all says “reject anything not listed”; ~all says “treat anything not listed as suspicious”. ~all is reasonable while you are still discovering senders; move to -all when the list is complete and DMARC is doing the enforcement.
Step 3: DKIM, per sender
Every service that sends as you should sign with a key for your domain. Setup is always the same pattern: the service gives you one or more DNS records to publish, usually CNAMEs or a long TXT record, at a name like selector._domainkey.example.com. Each service uses its own selector, so keys never collide, and you can add and remove senders independently.
dig +short TXT selector1._domainkey.example.com
dig +short CNAME s1._domainkey.example.com
Points that save time:
- Use 2048-bit keys where the service lets you choose. Long TXT records may need to be split into two quoted strings; most DNS control panels do that for you.
- Publish the records exactly as given. A stray space or a missing character invalidates the key.
- Use each service’s own verification button, then confirm with a real message (Step 6).
- If you cannot sign with your domain, a service may sign with its own domain instead. That passes DKIM, but it will not align with your From domain and will not help DMARC. Look for a “custom domain” or “domain authentication” setting.
Step 4: Understand alignment
DMARC passes when either SPF or DKIM passes and aligns:
- SPF alignment compares the domain in the message’s return path (also called envelope sender or bounce address) with the visible From domain. Many third-party services use their own bounce domain by default, so SPF passes but does not align. A custom return-path domain (a CNAME on your domain, for example
bounces.example.com) fixes that. - DKIM alignment compares the
d=domain in the signature with the From domain. Signing with your own domain (Step 3) aligns.
In practice: get DKIM aligned for every sender. It survives forwarding, which SPF does not, and it is the reliable half of DMARC.
Relaxed alignment is the default and is what you want: a signature from mail.example.com still aligns with a From of example.com.
Step 5: Publish DMARC, starting in monitor mode
DMARC is a TXT record at _dmarc.example.com. Start with a policy that changes nothing for delivery and gives you reports:
_dmarc.example.com. TXT "v=DMARC1; p=none; rua=mailto:[email protected]; fo=1"
p=nonemeans monitor only.rua=is where daily aggregate reports go. Use a mailbox you will actually read, or a service that turns the XML into a dashboard.
Leave it for two to four weeks. Read the reports: they list every source that sent mail claiming to be you, how many messages, and whether SPF and DKIM passed and aligned. Work through every source:
- Legitimate and passing: nothing to do.
- Legitimate and failing: fix its DKIM or return path (Steps 3 and 4).
- Unknown: investigate. It is either a forgotten service or someone spoofing your domain.
Step 6: Prove it with real messages
Send a test from each service to an address you control at a large provider, then open the message source and read the Authentication-Results header:
Authentication-Results: mx.example.net;
spf=pass smtp.mailfrom=bounces.example.com;
dkim=pass header.d=example.com;
dmarc=pass header.from=example.com
You want dmarc=pass, and dkim=pass with header.d equal to your domain. If dmarc=fail, the lines above tell you whether SPF or DKIM is the problem and which domain was used.
Step 7: Move to enforcement in steps
When the reports show all your legitimate senders aligned, tighten the policy gradually:
_dmarc.example.com. TXT "v=DMARC1; p=quarantine; pct=25; rua=mailto:[email protected]"
quarantine sends failing mail to spam; pct=25 applies it to a quarter of failing mail only. Raise pct over a couple of weeks (25, 50, 100), watching the reports and your own support inbox. Then move to p=reject. Subdomains follow the main policy unless you set sp=; if you have subdomains that send mail, check them in the reports before enforcing.
Why this matters more than it used to
Large mailbox providers now expect authenticated mail. Since 2024, Gmail and Yahoo require SPF and DKIM from bulk senders, with DMARC required for those sending in large volumes (Gmail’s threshold is about 5,000 messages a day), plus easy unsubscribe for marketing mail. Even below those thresholds, unauthenticated mail is the first to land in spam. And a published DMARC policy at reject is the best defence against someone sending fake invoices in your name.
A short checklist
- List every sender; remove the ones you no longer use.
- One SPF record, under ten lookups, ending
~allthen-all. - DKIM for each sender, with your own domain.
- A custom return path where the service supports it.
- DMARC at
p=nonewith reports for two to four weeks. - Test messages from each service; read
Authentication-Results. quarantinewith a risingpct, thenreject.
When it is worth getting help
Email authentication is the kind of work where one wrong record costs you a week of lost invoices, and nobody notices until a customer asks why they never received anything. If your domain sends from several places and you want it set up, tested from real inboxes and moved to enforcement safely, that is work I do regularly.
You can see my profile on Upwork or read about the email and DNS service. For more background, there is a plain-language explanation at SPF, DKIM and DMARC explained, and on the SiteHarbour blog a guide to rolling out DMARC from none to reject.