# Secure SMTP on port 587 not working

**URL:** <https://forum.mattermost.com/t/secure-smtp-on-port-587-not-working/8791>\
**Category:** Troubleshooting\
**Created:** [January 10, 2020, 10:25pm UTC](https://forum.mattermost.com/t/secure-smtp-on-port-587-not-working/8791 "2020-01-10T22:25:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![attzonko](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/attzonko/32/1335_2.png) [@attzonko](https://forum.mattermost.com/u/attzonko)\
**Post date:** [January 10, 2020, 10:25pm UTC](https://forum.mattermost.com/t/secure-smtp-on-port-587-not-working/8791/1 "2020-01-10T22:25:13Z")

</div>

#### Summary

Unable to enable secure SMTP connection.

#### Steps to reproduce

We are using Mattermost 5.18, until recently we were using non-secure SMTP on port 25, however starting in 2020 IT has disabled that option and we are only allowed to use SMTP with TLS 1.2 on port 587.

#### Expected behavior

I expect the SMTP “Test Connection” to be Successful.

#### Observed behavior

Instead what I see is the following error message:  
`Connection unsuccessful: Connection unsuccessful: SendMail: Failed to open TLS connection, tls: first record does not look like a TLS handshake`

---

<div class="post-metadata">

**Author:** ![attzonko](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/attzonko/32/1335_2.png) [@attzonko](https://forum.mattermost.com/u/attzonko)\
**Post date:** [January 10, 2020, 10:29pm UTC](https://forum.mattermost.com/t/secure-smtp-on-port-587-not-working/8791/2 "2020-01-10T22:29:20Z")

</div>

Here is what is in our config.json:

```
 "EmailSettings": {
        "EnableSignUpWithEmail": false,
        "EnableSignInWithEmail": false,
        "EnableSignInWithUsername": true,
        "SendEmailNotifications": true,
        "UseChannelInEmailNotifications": false,
        "RequireEmailVerification": false,
        "FeedbackName": "TechTalk",
        "FeedbackEmail": "techtalk@example.com",
        "ReplyToAddress": "test@example.com",
        "FeedbackOrganization": "",
        "EnableSMTPAuth": true,
        "SMTPUsername": "correct_username",
        "SMTPPassword": "correct_password",
        "SMTPServer": "correct_server_address",
        "SMTPPort": "587",
        "ConnectionSecurity": "TLS",
        "SendPushNotifications": false,
        "PushNotificationServer": "",
        "PushNotificationContents": "generic_no_channel",
        "EnableEmailBatching": false,
        "EmailBatchingBufferSize": 256,
        "EmailBatchingInterval": 30,
        "SkipServerCertificateVerification": true,
        "EmailNotificationContentsType": "full",
    },
```

---

<div class="post-metadata">

**Author:** ![PackElend](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/packelend/32/3261_2.png) [@PackElend](https://forum.mattermost.com/u/PackElend)\
**Post date:** [January 12, 2020, 4:35pm UTC](https://forum.mattermost.com/t/secure-smtp-on-port-587-not-working/8791/3 "2020-01-12T16:35:25Z")

</div>

faced the same issue but 465 and TLS works, so it is save to use 465.

---

<div class="post-metadata">

**Author:** ![attzonko](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/attzonko/32/1335_2.png) [@attzonko](https://forum.mattermost.com/u/attzonko)\
**Post date:** [January 13, 2020, 1:30am UTC](https://forum.mattermost.com/t/secure-smtp-on-port-587-not-working/8791/4 "2020-01-13T01:30:39Z")

</div>

Actually using port 587 is our only option. I I did manage to get it working.  
There were a couple of configuration issues on our end, I had to change from TLS to STARTTLS. I figured that out by using telnet to connect to the SMTP server and it mentioned STARTTLS, so I changed the setting in the Mattermost UI.

What ended up being the second problem was the username. Back when we were using non-secure SMTP server on port 25, the login included the domain (e.g. domain/username) for some reason I discovered that with the secure server on port 587, I had to remove the domain from the username to get the authentication to work.

---

<div class="post-metadata">

**Author:** ![PackElend](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/packelend/32/3261_2.png) [@PackElend](https://forum.mattermost.com/u/PackElend)\
**Post date:** [January 13, 2020, 9:06am UTC](https://forum.mattermost.com/t/secure-smtp-on-port-587-not-working/8791/5 "2020-01-13T09:06:34Z")

</div>

> [@attzonko](#):
>
> I figured that out by using telnet to connect to the SMTP server and it mentioned STARTTLS, so I changed the setting in the Mattermost UI.

did you do this in the mattermost container or in the host?

---

<div class="post-metadata">

**Author:** ![attzonko](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/attzonko/32/1335_2.png) [@attzonko](https://forum.mattermost.com/u/attzonko)\
**Post date:** [January 13, 2020, 10:48pm UTC](https://forum.mattermost.com/t/secure-smtp-on-port-587-not-working/8791/6 "2020-01-13T22:48:05Z")

</div>

Actually our instance is not currently running in a container, so to answer your question, I used telnet on the host to debug, and then once I figured it out, I changed the SMTP settings via the Mattermost UI.
