Skip to content

DKIM body hash did not verify: find what changed the message

Your DKIM key checks out, yet receivers report dkim=fail or dkim=neutral with "body hash did not verify". Something rewrote the body after signing; here is how to find the hop that did it and fix it there.

Offensly Team··Updated ·5 min read

Gmail marks your message dkim=neutral (body hash did not verify). Microsoft 365 writes dkim=fail (body hash did not verify) for the same mail. Meanwhile every DKIM record checker says your selector and key are fine. Both are true: the key is not the problem. Somebody changed the message body after it was signed.

Here is what that looks like in the headers of the received copy:

Authentication-Results: mx.google.com;
       dkim=neutral (body hash did not verify) header.i=@example.com header.s=s1 header.b=AbCdEfGh;
       spf=pass (google.com: domain of bounce@mail.example.net designates 192.0.2.10 as permitted sender) smtp.mailfrom=bounce@mail.example.net;
       dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=QUARANTINE) header.from=example.com

header.s=s1 is the selector, and the key behind it was found. The signature carries a hash of the body in its bh= tag (RFC 6376, section 3.5). The receiver hashed the body it got, the two hashes differed, and verification stopped there. RFC 6376 has the verifier compare the body hash before it checks the signature against the public key (section 6.1.3), so a wrong or missing DNS key produces a different error, never this one.

Body hash did not verify is not a key problem

Rotating the key or republishing the TXT record changes nothing here and can break signatures that pass today. Leave DNS alone unless you also see signature did not verify or no key for signature, which are different problems.

Also skip the l= body length tag some forum answers suggest. Appended footers stop breaking the signature, but section 8.2 explains why that lets anyone add content under it.

Find out where the body changed

Four common causes need four different fixes. Two checks tell them apart.

First, send a plain test message from the same system straight to a Gmail or Outlook.com mailbox you control. In Gmail open it, click More next to Reply, then Show original (Google describes the same path in its DKIM troubleshooting page). If that direct message also fails, the change happens on your side. If it passes and only some recipients report failures, something on the path to them changes the mail.

Second, in the failing copy, find the DKIM-Signature header with your d= domain and look at the Received headers above it. Each hop prepends its own header, so hops listed above the signature usually handled the message after it was signed:

Received: from gw.example.net (gw.example.net [198.51.100.7]) by mx.google.com ...
Received: from relay1.example.com (relay1.example.com [192.0.2.25]) by gw.example.net ...
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=example.com; s=s1;
        h=from:to:subject:date:message-id; bh=PLACEHOLDERbodyhash=; b=PLACEHOLDERsig...
Received: from app01.example.com by relay1.example.com ...

Here relay1 signed and gw.example.net handled the mail afterwards. That is your suspect. Note c=simple/simple too.

Now match the cause:

  1. Your own gateway adds content after signing. Direct tests fail, and the end of the body in Show original has a disclaimer, a "scanned by" banner or rewritten links that the author never wrote.
  2. A mailing list or forwarder rewrote the message. Direct tests pass. Failures come only for list posts or from one recipient organisation, and the body has a list footer or a [list-name] subject tag.
  3. Whitespace or encoding changed in transit. Direct tests fail intermittently, no visible text was added, and the signature uses c=simple for the body. A relay that converts 8-bit text to quoted-printable, rewraps long lines or strips trailing spaces breaks a simple body hash.
  4. Your app signs too early. You sign in your application or with a library, and a later stage adds a tracking pixel, unsubscribe footer or MIME wrapper. Direct tests fail every time from that one source.

Fix it where the change happens

Gateway after the signer (cause 1). Make the content change before signing, or have the last hop sign. In Microsoft 365, Microsoft's email authentication troubleshooting guide lists the order of options: configure ARC on the gateway, have the gateway DKIM-sign with your domain after its changes, or move footers and disclaimers into Microsoft 365 so they exist before Exchange Online signs. If Microsoft 365 still signs with the onmicrosoft.com domain, enable DKIM for your custom domain first. In Google Workspace, if you route through an outbound gateway, configure it so it does not alter outgoing messages, or let it sign.

Lists and forwarders (cause 2). You cannot fix someone else's list from your DNS. ARC exists for this: the intermediary seals the authentication results it saw before changing the mail. If you receive such mail in Microsoft 365, go to Email & collaboration > Policies & rules > Threat policies > Email authentication settings > ARC, select Add, and enter the d= domain from the intermediary's ARC-Seal header, not your own domain (Microsoft docs). The receiver's header then shows compauth=pass reason=130 even though DKIM still reads body hash did not verify.

Encoding (cause 3). Switch the signer to c=relaxed/relaxed. Relaxed body canonicalization reduces runs of whitespace to one space and ignores trailing whitespace (section 3.4.4), which survives most relay handling. Also send 7-bit-safe bodies: RFC 6376 section 5.3 says signers should convert to a suitable transfer encoding such as quoted-printable or base64 before signing, because a relay converting it afterwards breaks the hash.

Early signing (cause 4). Move signing to the last stage that modifies the message, normally the outbound MTA (OpenDKIM or the provider's own signing), not the application.

When a failing signature can stay as it is

DMARC needs one aligned pass, from SPF or from DKIM. A list that breaks DKIM on mail your domain sends is a known cost of p=quarantine or p=reject, which is part of why the move from DMARC p=none to enforcement goes in stages. If direct tests pass and failures show up only on list traffic, your signing is correct and can stay as it is; the list operator or the receiving side owns that fix.

What a modifying gateway costs you

In the header above, SPF passes for the sending service's bounce domain, which does not align with example.com, so DKIM was the only thing carrying DMARC. Under an enforcing policy, every message through that gateway lands in spam or bounces, for every recipient. The fix is a routing or signing change, not a DNS change. If SPF alignment is the weak spot instead, check the SPF lookup limit next.

Confirm the fix on a raw message

Save the received message as .eml (Download Original in Show original) and verify it locally with dkimverify from the dkimpy package, which reads the message on standard input and exits with 0 on a valid signature:

$ dkimverify < message.eml; echo $?
signature ok
0

Then confirm dkim=pass header.i=@example.com in Authentication-Results of a fresh test message, both direct and through the path that failed before. The free Offensly check reads your DKIM selector with SPF, DMARC and MX, no account needed, which rules out the key side before you chase the body.

Check your DKIM record for free

Check your own domain in seconds

The free check reads your SPF, DKIM, DMARC and MX records and tells you exactly what to fix. No sign-up.