Failed to close connection to the SMTP server: 550 header syntax
Summary
Mattermost notifications sent by email trigger a post-send SMTP error:
Steps to reproduce
Perform any operation that involves sending an email notification.
I am running Mattermost 5.34.2 via Gitlab Omnibus.
In the omnibus config file, I have these email settings for mattermost:
mattermost['env'] = {
'MM_SERVICESETTINGS_ENABLEINCOMINGWEBHOOKS' => 'true',
'MM_EMAILSETTINGS_ENABLESIGNUPWITHEMAIL' => 'false',
'MM_EMAILSETTINGS_ENABLESIGNINWITHEMAIL' => 'true',
'MM_EMAILSETTINGS_ENABLESIGNINWITHUSERNAME' => 'true',
'MM_EMAILSETTINGS_SENDEMAILNOTIFICATIONS' => 'true',
'MM_EMAILSETTINGS_REQUIREEMAILVERIFICATION' => 'true',
'MM_EMAILSETTINGS_SMTPUSERNAME' => '',
'MM_EMAILSETTINGS_SMTPPASSWORD' => '',
'MM_EMAILSETTINGS_SMTPSERVER' => 'localhost',
'MM_EMAILSETTINGS_SMTPPORT' => '25',
'MM_EMAILSETTINGS_CONNECTIONSECURITY' => nil
}
I also note that this is left at its default:
# mattermost['email_enable_batching'] = false
Suggesting that it shouldn't be using keepalive that might leave a connection dangling.
My config contains:
gitlab_rails['gitlab_email_from'] = 'git@example.com'
so there should always be a default from address available.
Expected behavior
Notification emails should be sent without errors.
Observed behavior
This error appears in the mattermost log:
{"level":"error","ts":1623262306.743317,"caller":"app/notification_email.go:106","msg":"Error while sending the email","user_email":"******@outlook.com","error":"failed to close connection to t
he SMTP server: 550 header syntax","errorVerbose":"550 header syntax\nfailed to close connection to the SMTP server\ngithub.com/mattermost/mattermost-server/v5/services/mailservice.SendMail\n\tgithub.c
om/mattermost/mattermost-server/v5/services/mailservice/mail.go:348\ngithub.com/mattermost/mattermost-server/v5/services/mailservice.sendMailUsingConfigAdvanced\n\tgithub.com/mattermost/mattermost-serv
er/v5/services/mailservice/mail.go:284\ngithub.com/mattermost/mattermost-server/v5/services/mailservice.SendMailWithEmbeddedFilesUsingConfig\n\tgithub.com/mattermost/mattermost-server/v5/services/mails
ervice/mail.go:252\ngithub.com/mattermost/mattermost-server/v5/services/mailservice.SendMailUsingConfig\n\tgithub.com/mattermost/mattermost-server/v5/services/mailservice/mail.go:256\ngithub.com/matter
most/mattermost-server/v5/app.(*EmailService).sendMailWithCC\n\tgithub.com/mattermost/mattermost-server/v5/app/email.go:702\ngithub.com/mattermost/mattermost-server/v5/app.(*EmailService).sendMail\n\tg
ithub.com/mattermost/mattermost-server/v5/app/email.go:695\ngithub.com/mattermost/mattermost-server/v5/app.(*EmailService).sendNotificationMail\n\tgithub.com/mattermost/mattermost-server/v5/app/email.g
o:691\ngithub.com/mattermost/mattermost-server/v5/app.(*App).sendNotificationEmail.func1\n\tgithub.com/mattermost/mattermost-server/v5/app/notification_email.go:105\ngithub.com/mattermost/mattermost-se
rver/v5/app.(*Server).Go.func1\n\tgithub.com/mattermost/mattermost-server/v5/app/server.go:973\nruntime.goexit\n\truntime/asm_amd64.s:1374"}
This appears in the exim log, and this aligns with the "header syntax" error:
2021-06-10 08:13:38 1lrFoo-0000O9-IS H=localhost (chat.example.com) [::1] F=<> rejected after DATA: header syntax (domain missing or malformed: failing address in "From:" header is: <@>): domain missing or malformed: failing address in "From:" header is: <@>
This does not appear to be a problem at the receiving end as it happens the same way for an outlook address, a gmail address, and another on a private server running a stock postfix.
Possible fixes
Unfortunately while this error message points at the location in the mattermost code base where this occurs, I can't see anything else about the SMTP conversation that happens prior to this. I would guess that Mattermost is leaving the connection open (though keepalive is disabled, as above) and not explicitly issuing a QUIT
when it's finished, and the connection is left to time out and trigger the error.
It seems unlikely to be a DNS issue because it's sending via localhost for this hop.
Given that the addresses I'm seeing with the first error are still arriving, and have a correct from address, I'm not sure whether this is related or not. Perhaps mattermost is sending the expected messages correctly, but then sending some others to the same recipients that are incorrectly formatted.