I am unable to setup the SMTP Server connection for Mattermost. I tried the docker setup with version 7.8.1 and 7.7.0 and currently tried the Ubuntu Omnibus installation (Mattermost Version: 7.8.0, Database Schema Version: 101), and I always get the same error.
Here is the Mattermost log, where I initially used port 465 with TLS, saved settings, and tested twice, then I changed the port to 25 and 587 both with STARTTLS and tested once each:
{"timestamp":"2023-03-08 06:09:28.749 Z","level":"info","msg":"SimpleWorker: Job is complete","caller":"jobs/base_workers.go:96","worker":"ProductNotices","job_id":"7qesrw671bb49nc9k1mps8breo"}
{"timestamp":"2023-03-08 06:49:42.842 Z","level":"warn","msg":"Unrecognized config permissions tag value.","caller":"api4/config.go:426","tag_value":"sysconsole_write_*_read"}
{"timestamp":"2023-03-08 06:49:42.897 Z","level":"warn","msg":"plugin configured with a nil SecureConfig","caller":"plugin/hclog_adapter.go:72","plugin_id":"com.mattermost.apps"}
{"timestamp":"2023-03-08 06:49:43.084 Z","level":"warn","msg":"plugin configured with a nil SecureConfig","caller":"plugin/hclog_adapter.go:72","plugin_id":"playbooks"}
{"timestamp":"2023-03-08 06:49:43.099 Z","level":"info","msg":"plugin process exited","caller":"plugin/hclog_adapter.go:61","plugin_id":"com.mattermost.apps","wrapped_extras":"pathplugins/com.mattermost.apps/server/dist/plugin-linux-amd64pid7666"}
{"timestamp":"2023-03-08 06:49:43.099 Z","level":"error","msg":"Unable to activate plugin","caller":"app/plugin.go:166","plugin_id":"com.mattermost.apps","error":"failed to ensure bot account: failed to set profile image: SetProfileImage: Couldn't upload profile image., "}
{"timestamp":"2023-03-08 06:49:43.224 Z","level":"info","msg":"plugin process exited","caller":"plugin/hclog_adapter.go:61","plugin_id":"playbooks","wrapped_extras":"pathplugins/playbooks/server/dist/plugin-linux-amd64pid7672"}
{"timestamp":"2023-03-08 06:49:43.224 Z","level":"error","msg":"Unable to activate plugin","caller":"app/plugin.go:166","plugin_id":"playbooks","error":"failed to ensure bot: failed to set profile image: SetProfileImage: Couldn't upload profile image."}
{"timestamp":"2023-03-08 06:49:48.713 Z","level":"warn","msg":"Error decoding the config","caller":"api4/system.go:202","path":"/api/v4/email/test","request_id":"144fatyu1bn4td11gihyubcujh","ip_addr":"127.0.0.1","user_id":"19kkfbshnfr3x85hfe8roagjka","method":"POST","error":"EOF"}
{"timestamp":"2023-03-08 06:49:58.714 Z","level":"error","msg":"Connection unsuccessful: unable to connect to the SMTP server through TLS: context deadline exceeded","caller":"web/context.go:117","path":"/api/v4/email/test","request_id":"144fatyu1bn4td11gihyubcujh","ip_addr":"127.0.0.1","user_id":"19kkfbshnfr3x85hfe8roagjka","method":"POST","err_where":"testEmail","http_code":500,"error":"testEmail: Connection unsuccessful: unable to connect to the SMTP server through TLS: context deadline exceeded"}
{"timestamp":"2023-03-08 07:08:05.275 Z","level":"warn","msg":"Error decoding the config","caller":"api4/system.go:202","path":"/api/v4/email/test","request_id":"ukunea7d47dsixa1nowezfsjrh","ip_addr":"127.0.0.1","user_id":"19kkfbshnfr3x85hfe8roagjka","method":"POST","error":"EOF"}
{"timestamp":"2023-03-08 07:08:15.277 Z","level":"error","msg":"Connection unsuccessful: unable to connect to the SMTP server through TLS: context deadline exceeded","caller":"web/context.go:117","path":"/api/v4/email/test","request_id":"ukunea7d47dsixa1nowezfsjrh","ip_addr":"127.0.0.1","user_id":"19kkfbshnfr3x85hfe8roagjka","method":"POST","err_where":"testEmail","http_code":500,"error":"testEmail: Connection unsuccessful: unable to connect to the SMTP server through TLS: context deadline exceeded"}
Here is the server log for first testing with port 465 TLS and then 25 STARTTLS:
Mar 8 08:21:35 mail-02 postfix/smtps/smtpd[2343378]: connect from <ptr_record>[<mattermost_public_ip>]
Mar 8 08:21:35 mail-02 postfix/smtps/smtpd[2343378]: SSL_accept error from <ptr_record>[<mattermost_public_ip>]: lost connection
Mar 8 08:21:35 mail-02 postfix/smtps/smtpd[2343378]: lost connection after CONNECT from <ptr_record>[<mattermost_public_ip>]
Mar 8 08:21:35 mail-02 postfix/smtps/smtpd[2343378]: disconnect from <ptr_record>[<mattermost_public_ip>] commands=0/0
Mar 8 08:22:02 mail-02 postfix/postscreen[2343612]: CONNECT from [<mattermost_public_ip>]:60569 to [<mail_server_private_ip>]:25
Mar 8 08:22:02 mail-02 postfix/postscreen[2343612]: PASS OLD [<mattermost_public_ip>]:60569
Mar 8 08:22:12 mail-02 postfix/smtpd[2343613]: connect from <ptr_record>[<mattermost_public_ip>]
Mar 8 08:22:12 mail-02 postfix/smtpd[2343613]: lost connection after CONNECT from <ptr_record>[<mattermost_public_ip>]
Mar 8 08:22:12 mail-02 postfix/smtpd[2343613]: disconnect from <ptr_record>[<mattermost_public_ip>] commands=0/0
I have verified that I can access the mail server from the Mattermost server bash:
root@mattermost:/usr/bin# telnet mail.mydomain.com 25
Trying <mailserver_ip>...
Connected to mail.mydomain.com.
Escape character is '^]'.
HELO morpheus@mydomain.com
220 mail-02.mydomain.com ESMTP Postfix
250 mail-02.mydomain.com
QUIT
221 2.0.0 Bye
Connection closed by foreign host.
root@mattermost:/usr/bin# telnet mail.mydomain.com 465
Trying <mailserver_ip>...
Connected to mail.mydomain.com.
Escape character is '^]'.
Connection closed by foreign host.
root@mattermost:/usr/bin# telnet mail.mydomain.com 587
Trying <mailserver_ip>...
Connected to mail.mydomain.com.
Escape character is '^]'.
220 mail-02.mydomain.com ESMTP Postfix
HELO morpheus@mydomain.com
250 mail-02.mydomain.com
QUIT
221 2.0.0 Bye
Connection closed by foreign host.
root@mattermost:/usr/bin#
I am at a loss where the problem could be. I can send mails from thunderbird using these server settings without a problem.