What the message looks like
Authentication-Results: mx.google.com;
dkim=fail (body hash did not verify) header.i=@example.com header.s=default header.b=abc123;
spf=pass smtp.mailfrom=example.comCommon causes
- A mail gateway or antivirus adds a footer or banner after your server signed the message.
- A mailing list or a forwarder changes the subject, the text or adds an unsubscribe footer.
- Link tracking or URL rewriting modifies the body.
- Strict canonicalization (
simple) breaks on small changes such as whitespace or line endings. - The message is signed before another filter, or signed twice with different keys.
Check
- Look at the signature and the result in the headers of a received test mail
grep -iE '^(dkim-signature|authentication-results)' message.eml - Is the DNS key published and valid?
- Test the key on the signing server
opendkim-testkey -d example.com -s default -vvv - Which canonicalization is configured?
grep -i Canonicalization /etc/opendkim.conf
Fix
- Make signing the very last step, after antivirus, disclaimer and filter, just before sending.
- Use relaxed canonicalization:
Canonicalization relaxed/relaxed. - Remove or move footers and banners that are added after signing, or add them before.
- Turn off link rewriting for your own outgoing mail, or sign after it.
- For mailing lists, rely on SPF alignment and a
p=noneorquarantineDMARC policy; lists change messages by design.
Typical scenario
Mail from your Postfix server, signed by OpenDKIM, usually arrives at Gmail with dkim=pass. Since you installed a disclaimer service, messages with attachments show "dkim=fail (body hash did not verify)". The disclaimer appends text to the body after OpenDKIM has signed. In Gmail open "Show original" and check whether the footer is in the text; then the milter order is the first thing to change.
FAQ
What is the difference to “signature did not verify”?
“Body hash did not verify” means the text changed. “Signature did not verify” usually means the DNS key does not match the private key, or the signed headers changed.
Does a DKIM failure always mean spam?
No. If SPF passes and is aligned, DMARC can still pass. But a broken DKIM weakens your delivery, so fix it.
In which order should the milters run?
OpenDKIM must sign last. In smtpd_milters and non_smtpd_milters it therefore goes at the end of the list, after virus scanner, disclaimer and spam filter. Anything that changes the body or certain headers after signing invalidates the signature.
What is the difference between simple and relaxed?
simple requires headers and body to stay byte-identical. relaxed tolerates small changes such as folded whitespace, lowercase header names and re-wrapped lines. It does not help for the body, though, when text is added or replaced.
Does the l= tag help to allow footers?
With l= only part of the body is signed, so appended text is ignored. That is risky, since attackers can append content as well, and it is therefore not recommended. It is cleaner to add footers before signing.