Mattermost, Inc.

DKIM failure for Mattermost system emails - 'message has been altered'

Summary

My emails from Mattermost are failing DKIM checks and showing up in Gmail as spam.

Steps to reproduce

Mattermost Version: 5.19.1
Database Schema Version: 5.19.0
Database: mysql

My Mattermost instance has a SiteURL set to a subdomain of chat.example.com. SSL is working. It’s running in an AWS EC2 instance, which was created from a Bitnami image.

The SMTP settings in Mattermost are:
SMTP Server: example.com
SMTP Server Port: 465
Enable SMTP Authentication: true
SMTP Server Username: chat@example.com
Connection Security: TLS
Skip Server Certificate Verification: false
Enable Security Alerts: true

My DKIM record is:
v=DKIM1; k=rsa; c=relaxed/relaxed; d=example.com; p=[DKIM-key redacted]

My SPF record is:
v=spf1 +mx +a +ipx:xxx:xxx:xx +include:google.com +include:mailgun.org +include:[IP of the EC2 instance] ~all

Expected behavior

Expect the emails from Mattermost to pass DKIM since they’re under an allowed domain.

Observed behavior

I have DKIM, SPF and DMARC set up on my mail server. I send email via Gmail using SMTP and these emails pass all checks. When Mattermost sends emails through the same server by SMTP, emails pass SPF but fail DKIM with this message from Gmail:
dkim=fail header.i=@example.com header.s=default header.b=YXmrE5yx;

Sending email to dkimvalidator.com results in this message for DKIM:
Validating Signature
result = fail
Details: message has been altered

I’m a bit lost on next steps for how to troubleshoot this further; would appreciate your thoughts.