Prompt
How do I debug SPF or DKIM failures on a sending domain?
Latest observation
To debug SPF or DKIM failures on a sending domain, work from the DNS records, then the actual message headers, then the sending path. The key is to determine what domain was authenticated, what domain was supposed to authenticate, and where the alignment broke.
1) Confirm the failure type
First, identify whether the problem is:
- SPF fail: the sending IP is not authorized for the domain used in the envelope-from/return-path.
- DKIM fail: the message signature is invalid, missing, or the public key lookup fails.
- DMARC fail: SPF and/or DKIM may pass individually, but not with alignment to the From: domain.
Check the delivered message headers for:
Authentication-Results:Received-SPF:DKIM-Signature:From:Return-Path:
2) Inspect the message headers
Look at the headers of a failed email and identify:
- From domain — the visible sender domain
- Envelope-from / Return-Path — the domain SPF evaluates
- DKIM d= — the signing domain
- Sending IP — the IP that actually sent the message
- Authentication-Results — the receiver’s verdict
Example:
Authentication-Results: mx.example.net;
spf=fail smtp.mailfrom=bounce@example-sender.com;
dkim=fail header.d=example-sender.com;
dmarc=fail header.from=example-sender.com
This tells you:
- SPF checked
smtp.mailfrom=example-sender.com - DKIM signed with
d=example-sender.com - DMARC failed because neither aligned/passed appropriately
3) Debug SPF
Check the SPF record
Look up the SPF TXT record for the domain used in the Return-Path / MAIL FROM identity:
dig txt example-sender.com
You should have a record like:
v=spf1 include:_spf.google.com ip4:203.0.113.10 -all
Common SPF problems
- Missing sending IP: the mail is sent from an IP not listed in SPF
- Too many DNS lookups: SPF exceeds the 10-lookup limit
- Multiple SPF records: more than one
v=spf1TXT record - Wrong domain checked: SPF uses the envelope-from domain, not the visible From domain
- Forwarding/NAT: intermediary systems change the sending IP
- Softfail vs fail:
~allmay be treated leniently;-allis strict
Check SPF evaluation
Use a tester or inspect receiver logs. If needed, simulate using the sending IP and MAIL FROM domain. Some common tools:
- MXToolbox SPF lookup
- dmarcian SPF checker
dig- Postfix/Exchange logs
4) Debug DKIM
Check the DKIM signature
In the message headers, find:
DKIM-Signature: v=1; a=rsa-sha256; d=example-sender.com; s=selector1; ...
Key fields:
d=signing domains=selectorh=headers signedbh=body hashb=signature value
Verify the DNS key exists
Look up:
dig txt selector1._domainkey.example-sender.com
You should see a TXT record containing the public key, e.g.:
v=DKIM1; k=rsa; p=MIIBI...
Common DKIM problems
- Wrong selector: DNS record doesn’t match
s= - Missing public key: no TXT record at
selector._domainkey.domain - Signature broken in transit: body or headers modified after signing
- Key rotation mismatch: signer uses a new private key, DNS still has old public key
- Canonicalization issues: whitespace/header changes invalidate signature
- Line wrapping or MIME changes by mailing list software, gateways, or disclaimers
5) Check DMARC alignment
Even if SPF or DKIM passes, DMARC can fail if the authenticated domain doesn’t align with the visible From: domain.
For DMARC:
- SPF aligns when the authenticated MAIL FROM/HELO domain aligns with
From: - DKIM aligns when
d=aligns withFrom:
Example:
From: user@example.com- SPF passes for
bounce@mailer.example.net→ may not align - DKIM passes for
d=mailer.example.net→ may not align - Result: DMARC fail
6) Test the sending path
Confirm what system actually sent the mail:
- MTA logs
- ESP logs
- Application mail settings
- SMTP relay host
- Envelope-from configuration
Common misconfigurations:
- App uses one From domain, relay uses another bounce domain
- ESP is signing with its domain instead of yours
- Shared IP not included in SPF
- New region/IP not added to SPF
- Signing key not deployed everywhere
7) Use dedicated diagnostic tools
Useful checks:
dig txt domain.comdig txt selector._domainkey.domain.com- MXToolbox SPF/DKIM/DMARC lookup
- dmarcian Inspector
- Google Admin Toolbox Check MX
openssl/mail header inspection tools if you have raw source
8) A quick troubleshooting checklist
- Find the failed message headers.
- Identify:
From:Return-Path:DKIM-Signature d=- sending IP
- Compare sending IP to SPF record.
- Verify DKIM selector and public key DNS record.
- Check whether DMARC alignment is the real failure.
- Look for message modification after signing.
- Review MTA/ESP logs for the exact outbound configuration.
9) Typical fixes
- Add the actual sending IP or include the relay’s SPF mechanism
- Remove duplicate SPF records
- Keep SPF under the 10 DNS-lookup limit
- Publish the correct DKIM selector public key
- Ensure the signer domain aligns with your From domain for DMARC
- Sign as close to final delivery as possible to avoid body/header changes
- Update bounce/return-path domain to align with From if needed
If you want, I can also give you:
- a step-by-step debugging workflow using sample headers, or
- a command list to diagnose SPF/DKIM from the terminal.