Skip to main content

DKIM on Zimbra and Rules That Change Messages

A rule that adds a signature, a disclaimer or a banner changes the message. DKIM is there to prove that nobody changed the message on its way, so the two look like a bad match. On Zimbra they are not: the rules of MSH Zimbra Rules run before Zimbra signs outgoing mail, so the signature covers what the rules added. This article shows where each step sits, how to check it on your server, and what to do about the other direction, incoming mail that a rule changes after the sender signed it.

How DKIM signs a message​

The sending server adds a DKIM-Signature header with two values that matter here:

  • bh=, a hash of the body, and
  • b=, a signature over the headers listed in h= and the body hash, made with the domain's private key.

The receiving server takes the public key from DNS (<selector>._domainkey.<domain>), computes the body hash again and checks the signature. With the usual relaxed canonicalization, changes of white space at the ends of lines do not count. Anything else does:

Change after signingResult at the recipient
A line added to the body, such as a footer or a disclaimerdkim=fail (body hash did not verify)
A header listed in h= changed, such as Fromdkim=fail (signature verification failed)
A header not listed in h= changedStill dkim=pass
A header addedStill dkim=pass

So the only question is whether a change happens before or after the signature.

Where MSH Zimbra Rules sits in the mail path​

The milter of MSH Zimbra Rules is registered on the Postfix of the Zimbra MTA that receives the message, before Amavis. Zimbra signs outgoing mail with OpenDKIM, a milter on a second Postfix service, port 10030, to which Amavis hands mail from your own users:

Outgoing mail on a Zimbra server. A web or mail client sends the message over SMTP to Postfix, where the MSH Zimbra Rules milter adds signatures, disclaimers and banners. Postfix passes it to Amavis on port 10026, Amavis to Postfix on port 10030, where the OpenDKIM milter signs the message as it is now. Then Amavis on port 10032 and Postfix on port 10025 send it on to the recipient&#39;s server, which verifies the signature. Everything up to the signing is before signing, where changes are safe; after it the message is signed and must not change.

Outgoing mail on a Zimbra server. A web or mail client sends the message over SMTP to Postfix, where the MSH Zimbra Rules milter adds signatures, disclaimers and banners. Postfix passes it to Amavis on port 10026, Amavis to Postfix on port 10030, where the OpenDKIM milter signs the message as it is now. Then Amavis on port 10032 and Postfix on port 10025 send it on to the recipient&#39;s server, which verifies the signature. Everything up to the signing is before signing, where changes are safe; after it the message is signed and must not change.

Everything MSH Zimbra Rules adds to an outgoing message is in place when OpenDKIM signs it. Zimbra's own domain disclaimer, if you use it, is added by Amavis on port 10026, also before signing. After the signature, Zimbra only adds headers such as Received and X-Spam-Status, which do not break it.

The defaults of Zimbra's OpenDKIM are rsa-sha256, relaxed/relaxed, and the headers Date, From, To, Message-ID and MIME-Version in h=. The Subject is not signed.

Step 1 - Check the order on your server​

The domain has a DKIM key. Zimbra signs only for domains with a key. Show it, or create one with -a and publish the TXT record it prints in DNS:

sudo su - zimbra -c '/opt/zimbra/libexec/zmdkimkeyutil -q -d example.com'

The tool is in /opt/zimbra/libexec, which is not on the path of the zimbra user, so give the full path.

The milter of MSH Zimbra Rules is registered on Postfix:

sudo su - zimbra -c 'postconf smtpd_milters'

The output lists inet:localhost:9011, see Milter configuration.

A message shows the order. Send a message from the web client to a colleague on the same server and open its headers. In the Modern web client, open the message and click Headers. Read the Received headers from the bottom up:

  1. Postfix receives the message from the web client. The rules run here.
  2. amavis, port 10026.
  3. Postfix again, with the queue ID that the DKIM-Filter header names, and the DKIM-Signature header right above it: OpenDKIM signed the message here.
  4. amavis, port 10032, then Postfix and the delivery over LMTP.
A message from Aisha Okafor in the Modern web client, with the signature and the webinar banner that signature rules added
Step 1 of 3

The signature and the banner were added by signature rules.

We checked such a message against the public key of its domain. The body hash and the signature both verified, with the rule's signature and banner in the body. With one character of the body changed, the check failed with body hash did not verify. With [EXTERNAL] put before the subject, it still passed, since Zimbra does not sign the Subject.

Step 2 - Check a received message for dkim=pass​

Send a message from your server to a mailbox at a large mail service and open its original source there. In Gmail, that is Show original in the menu of the message, which shows DKIM: 'PASS' with domain example.com. Other services write the result to the Authentication-Results header:

Authentication-Results: mx.example.net;
dkim=pass header.d=example.com header.s=<selector>

Check a message that a rule changed: one with a signature from a signature rule or a disclaimer from a disclaimer rule. If it passes, the order is right.

Incoming mail: verify DKIM before the rules change it​

The other direction is where a rule does break a signature. A rule that puts [EXTERNAL] before the subject of incoming mail, or adds a note to its body, changes a message that the sender already signed. Large senders usually sign the Subject too. Amavis and SpamAssassin check DKIM after the milter, so they see the changed message, take the sender's valid signature for a broken one and score it as such. For mail from a domain with a strict DMARC policy that can be enough for Junk.

DKIM verification fixes this. The milter verifies the signatures of every incoming message before any rule changes it, and writes the result to an Authentication-Results header under the server name you set. Open Settings > DKIM Verification:

  1. Tick Verify DKIM signatures of incoming messages.
  2. Enter the Server name in the result header, for example mail.example.com.
  3. Click Save Settings.
The DKIM Verification page with the verification off, and DKIM Verification selected in the Settings section of the navigation
Step 1 of 4

Open Settings > DKIM Verification.

Then make Amavis and SpamAssassin use that result instead of their own check: turn off the DKIM verification of Amavis and add the SpamAssassin rules file of DKIM configuration, or on every MTA server of a multi-server installation. If no rule of yours changes the subject or the body of incoming mail, you do not need the DKIM configuration. A message banner or a sender tag travels in a header and leaves the signature intact.

Test it in the Rules tester​

The Rules tester can set the DKIM result that the verification would have found. With a policy rule that puts [EXTERNAL] before the subject of incoming mail (Modify subject with the condition Message > Direction, Incoming), open Rules Tester > New message > Custom... and:

  1. Enter a From address of another domain, such as partner@northwind.example, and one of your users in To.
  2. On the SMTP tab, enter a Client address, Server port 25, DKIM result pass and DKIM signing domain northwind.example.
  3. Click Send and open the message.
The SMTP tab of a custom test message with Server port 25, HELO name mail.northwind.example, DKIM result pass and DKIM signing domain northwind.example
Step 1 of 3

DKIM result pass for the domain northwind.example.

The tester shows the result in the trace only. In real mail it is the Authentication-Results header under your server name, which the DKIM result condition and, with DKIM configuration, SpamAssassin read.

Troubleshooting dkim=fail (body hash did not verify)​

The body changed after the signature. Find out where:

  • Your outgoing mail fails at every recipient. Something after Zimbra changes the message: an outbound gateway or relay host that adds a footer, scans and rewrites links, or converts the encoding. Compare the message in the Sent folder with the original at the recipient. Add the footer with a disclaimer rule instead, so it is signed with the message, or let the last server on the way sign.
  • It fails only at some recipients. Their mailing list or forwarder added a footer or a subject prefix. That is normal for lists and not a problem of your server.
  • It fails for mail from outside, in your own Junk folder. A rule of yours changed the body or the subject of incoming mail and Amavis checked it afterwards. Turn on DKIM verification and DKIM configuration.

Other results mean other things:

ResultMeaning
signature verification failedThe body is fine, a signed header changed, or the TXT record in DNS does not match the private key.
no key for signatureThe TXT record of the selector is missing in DNS. Check the domain's key in Step 1.
temperrorThe DNS lookup of the key failed at the recipient. It usually goes away on the next try.

Good to know​

  • Zimbra changes the encoding before signing. Amavis on port 10026 makes Postfix convert 8-bit messages to 7-bit before OpenDKIM signs them, so no relay has to convert them later and break the body hash.
  • Changing the subject does not break Zimbra's own signatures, because Zimbra does not sign it. Other senders do, so a subject rule on incoming mail still needs DKIM verification.
  • A passing signature is no proof of a good message. Spam signed by the spammer's own domain passes too. See the warning on the DKIM result condition.

Want to try it on your own server? Start a free trial.