SPF, DKIM and DMARC Alignment: Why Mail Lands in Spam When Every Record Looks Green
SPF checks the envelope sender, DKIM the signer, and DMARC whether either aligns with the From line. Why alignment should rest on DKIM, step by step record examples, moving from monitoring to reject, and pitfalls from report authorization to new senders.
One day the password reset email your application sends starts landing in spam, or stops arriving altogether. You check the records: SPF is there, DKIM signatures are there, a DMARC record exists. The problem is usually not any of these mechanisms on its own but how they relate to each other. A receiving server answers "did this message really come from the domain in the From line" through DMARC alignment, and alignment is the most commonly misunderstood piece.
Three mechanisms, three different domains
A message carries at least three domains that can be authenticated, and that is where the confusion starts.
SPF checks the envelope sender, the MAIL FROM value of the SMTP session (recorded in the message as Return-Path). It has nothing to do with the From: header the user sees. If you send through an email service provider, the envelope address is often the provider's own domain, and SPF passes against their record, not yours.
DKIM signs headers and body. The d= tag in the signature tells you who signed it. That does not have to match From: either; providers sign with their own domain by default.
DMARC adds one rule on top: at least one of SPF or DKIM must pass and the domain it passed for must be aligned with the domain in the From: header. An unaligned SPF pass does not count as a DMARC pass. Most cases where the dashboard is all green but messages get rejected come down to this.
Alignment has two modes. In relaxed mode (the default) the organizational domain has to match: From: example.com is aligned with d=mail.example.com. Strict mode requires an exact match. Unless you have a concrete reason for strict mode, stay relaxed; strict mode quietly breaks the first service that sends from a subdomain.
Which one to rely on: SPF or DKIM
My position is clear: build alignment on DKIM and keep SPF as a supporting signal.
SPF breaks under forwarding. When a user auto-forwards mail to another mailbox, the message leaves from the forwarder's IP, which is not in your SPF record. A DKIM signature stays valid along the way as long as the message is not modified. SPF also has a hard limit: evaluation may trigger at most 10 DNS lookups. include, a, mx, exists and redirect all count, nested includes included. Add three or four providers and you exceed it and get a permerror, which many receivers treat as a failure.
DKIM has its own weak spot: mailing lists that prefix the subject line or append a footer break the signature. Having both aligned is the most robust state, but if you have to pick one, pick DKIM.
Setting it up step by step
The example domain is example.com, sending through an email provider.
1. SPF record. A single TXT record at the domain apex:
example.com. TXT "v=spf1 include:_spf.provider.example -all"
The domain must not have more than one v=spf1 record; two records produce permerror. When adding a provider, add an include to the existing record instead of creating a new one.
2. Custom envelope address. If your provider supports it, move the envelope address to your own subdomain (usually called "custom return path" or "custom MAIL FROM"). Typically you add a CNAME or MX record the provider gives you for bounce.example.com. Now the SPF pass is aligned with example.com in relaxed mode.
3. DKIM. Enable signing with your domain in the provider's dashboard. Most providers give you a CNAME for the selector:
s1._domainkey.example.com. CNAME s1.dkim.provider.example.
Delegating through a CNAME leaves key rotation to the provider. If you publish the key yourself, use at least 2048 bits and check that your DNS panel splits the long TXT value into 255 character strings correctly.
4. DMARC, in monitoring mode first:
_dmarc.example.com. TXT "v=DMARC1; p=none; rua=mailto:[email protected]"
The rua address receives daily aggregate reports (XML) from receivers. These reports are the only reliable source showing who sends mail on behalf of your domain. This is where you find the forgotten invoicing system, marketing tool or helpdesk software.
5. Verify. Check the records from the command line:
dig +short TXT example.com
dig +short TXT s1._domainkey.example.com
dig +short TXT _dmarc.example.com
Then send a message to your own mailbox and read the Authentication-Results line in the raw headers. You want spf=pass, dkim=pass and dmarc=pass, and the header.d value on the DKIM line should be your domain, not the provider's.
6. Tighten the policy. Once every legitimate sender shows up aligned in the reports, move to p=quarantine, and a few weeks later to p=reject. Use the sp= tag if subdomains need a separate policy.
Pitfalls
A report address on another domain needs an authorization record. If rua points to a different domain, receivers verify that the target domain accepts reports for you. Without a TXT record named example.com._report._dmarc.reports.example.net with the value v=DMARC1 on the target domain, reports are silently not sent.
Non-sending domains are left unprotected. Domains you bought only for a website, or registered to catch typos, are ideal for spoofing. Give them v=spf1 -all, a DMARC record with p=reject, and if possible a "null MX" (MX 0 .).
The ~all versus -all debate is overrated. On a domain enforcing DMARC with p=reject, DMARC makes the final call. What matters is that SPF passes aligned or DKIM is aligned.
Do not use the l= tag in DKIM. It lets the signature cover only the first part of the body, so an attacker can append content to a signed message.
Adding a new sender breaks DMARC. If you are at p=reject and start sending from a new SaaS tool under your domain, all of its mail gets rejected until DKIM is configured. Make DKIM setup a precondition before any new sender goes live.
Move bulk mail to a separate subdomain. If marketing mail and transactional mail (password resets, invoices) leave from the same domain, one campaign's complaint rate drags down the reputation of your transactional mail. Large mailbox providers now expect bulk senders to have SPF, DKIM, aligned DMARC, a one-click unsubscribe header and a low complaint rate; meeting these on a marketing subdomain isolates the main domain from that risk.
When you do not need all of this
If your application only sends notifications to your own mail server on an internal network and nothing leaves for the outside world, this setup is overkill. But if your domain has any reputation outside, publishing at least a DMARC record with p=reject costs nothing even if you never send mail, and it largely prevents your domain from being used for spoofing.
In short, do not ask "do we have SPF and DKIM". Ask "is the domain in the From: line aligned with the domain of the mechanism that passed". Answer it from DMARC reports and the Authentication-Results header, not by guessing.