# TLS Connection Error SendMail tls: first record does not look like a TLS handshake

**URL:** <https://forum.mattermost.com/t/tls-connection-error-sendmail-tls-first-record-does-not-look-like-a-tls-handshake/7283>\
**Category:** Troubleshooting\
**Created:** [May 14, 2019, 7:16am UTC](https://forum.mattermost.com/t/tls-connection-error-sendmail-tls-first-record-does-not-look-like-a-tls-handshake/7283 "2019-05-14T07:16:21Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![marutinandanpandya](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/marutinandanpandya/32/2889_2.png) [@marutinandanpandya](https://forum.mattermost.com/u/marutinandanpandya)\
**Post date:** [May 14, 2019, 7:16am UTC](https://forum.mattermost.com/t/tls-connection-error-sendmail-tls-first-record-does-not-look-like-a-tls-handshake/7283/1 "2019-05-14T07:16:21Z")

</div>

I created an IAM User with SES access for SMTP in AWS. Even the test email fails with the following error.

> {“level”:“error”,“ts”:1557817125.2576823,“caller”:“web/context.go:52”,“msg”:“Connection unsuccessful: SendMail: Failed to open TLS connection, tls: first record does not look like a TLS handshake”,“path”:“/api/v4/email/test”,“request\_id”:“XXXnpxm97ffhzp9cgixiXXXXX”,“ip\_addr”:“157.37.133.140”,“user\_id”:“”,“method”:“POST”,“err\_where”:“testEmail”,“http\_code”:500,“err\_details”:“”}

Enabled SMTP Auth is set to true  
SMTP server: [email-smtp.us.east-1.amazonaws.com](http://email-smtp.us.east-1.amazonaws.com)  
SMTP port: 587  
SMTP username: User access\_key  
SMTP Password: secret\_key  
Connection is TLS

iam policy attached is

> ```
> {
> "Version": "2012-10-17",
> "Statement": [
> {
> "Sid": "VisualEditor0",
> "Effect": "Allow",
> "Action": [
> "ses:SendEmail",
> "ses:SendRawEmail"
> ],
> "Resource": "*"
> }
> ]
> }
> 
> ```

Mattermost Versions Test: 5.10, 5.9.1

---

<div class="post-metadata">

**Author:** ![amy.blais](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/amy.blais/32/7481_2.png) [@amy.blais](https://forum.mattermost.com/u/amy.blais)\
**Post date:** [May 14, 2019, 3:33pm UTC](https://forum.mattermost.com/t/tls-connection-error-sendmail-tls-first-record-does-not-look-like-a-tls-handshake/7283/2 "2019-05-14T15:33:41Z")

</div>

Hi @marutinandanpandya,

Wondering if this previous thread might help: [[solved] TLS Connection Error SendMail Failed to Open TLS - on SES Amazon SMTP credentials in Config/Mattermost JSON](https://forum.mattermost.com/t/solved-tls-connection-error-sendmail-failed-to-open-tls-on-ses-amazon-smtp-credentials-in-config-mattermost-json/7104)?

---

<div class="post-metadata">

**Author:** ![marutinandanpandya](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/marutinandanpandya/32/2889_2.png) [@marutinandanpandya](https://forum.mattermost.com/u/marutinandanpandya)\
**Post date:** [May 14, 2019, 3:59pm UTC](https://forum.mattermost.com/t/tls-connection-error-sendmail-tls-first-record-does-not-look-like-a-tls-handshake/7283/3 "2019-05-14T15:59:45Z")

</div>

Nope. Already saw that.  
As the person mentioned he was testing with the wrong creds and fixing the creds solved the issue.

Same is not the case here, I created the IAM User specifically with SES access and yet the issue. (Also tried sending emails with user having administrative access, yet the same issue)

---

<div class="post-metadata">

**Author:** ![amy.blais](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/amy.blais/32/7481_2.png) [@amy.blais](https://forum.mattermost.com/u/amy.blais)\
**Post date:** [May 20, 2019, 2:49pm UTC](https://forum.mattermost.com/t/tls-connection-error-sendmail-tls-first-record-does-not-look-like-a-tls-handshake/7283/4 "2019-05-20T14:49:56Z")

</div>

Hi @marutinandanpandya, can you try using port [456 or 2456](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-connect.html)?

---

<div class="post-metadata">

**Author:** ![djangofan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/djangofan/32/3650_2.png) [@djangofan](https://forum.mattermost.com/u/djangofan)\
**Post date:** [March 29, 2020, 2:18am UTC](https://forum.mattermost.com/t/tls-connection-error-sendmail-tls-first-record-does-not-look-like-a-tls-handshake/7283/5 "2020-03-29T02:18:28Z")

</div>

I am having the exact same issue but there is not quite enough information on this thread to resolve me. I’m using AWS SES email service: [email-smtp.us-east-1.amazonaws.com](http://email-smtp.us-east-1.amazonaws.com). I get 1 of a few errors:

1. TLS 587: Connection unsuccessful: Connection unsuccessful: SendMail: Failed to open TLS connection, tls: first record does not look like a TLS handshake
2. TLS 465: Connection unsuccessful: Connection unsuccessful: SendMail: Error setting “From Address”, 501 Invalid MAIL FROM address provided
3. TLS 25: hangs, and nothing shows up in the log
4. STARTTLS 465: times out and then says Connection unsuccessful: Connection unsuccessful: SendMail: Failed to open TLS connection, EOF

---

<div class="post-metadata">

**Author:** ![amy.blais](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/amy.blais/32/7481_2.png) [@amy.blais](https://forum.mattermost.com/u/amy.blais)\
**Post date:** [March 30, 2020, 12:31pm UTC](https://forum.mattermost.com/t/tls-connection-error-sendmail-tls-first-record-does-not-look-like-a-tls-handshake/7283/6 "2020-03-30T12:31:12Z")

</div>

What are your SMTP settings set to?

---

<div class="post-metadata">

**Author:** ![ahmaddanial](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/ahmaddanial/32/2938_2.png) [@ahmaddanial](https://forum.mattermost.com/u/ahmaddanial)\
**Post date:** [April 2, 2020, 6:22am UTC](https://forum.mattermost.com/t/tls-connection-error-sendmail-tls-first-record-does-not-look-like-a-tls-handshake/7283/7 "2020-04-02T06:22:27Z")

</div>

Hi, @djangofan

Let us troubleshoot this based on the information provided in the official [SMTP Email Setup](https://docs.mattermost.com/install/smtp-email-setup.html#amazon-ses):

- Set **SMTP Username** to **[YOUR\_SMTP\_USERNAME]**
- Set **SMTP Password** to **[YOUR\_SMTP\_PASSWORD]**
- Set **SMTP Server** to **[email-smtp.us-east-1.amazonaws.com](http://email-smtp.us-east-1.amazonaws.com)**
- Set **SMTP Port** to **465**
- Set **Connection Security** to **TLS**

With reference to the following error that you are getting:

> [@djangofan](#):
>
> TLS 465: Connection unsuccessful: Connection unsuccessful: SendMail: Error setting “From Address”, 501 Invalid MAIL FROM address provided

Let us take a look at your Mattermost email settings. Can you please run the following command on the terminal and provide the result with the sensitive information such as password redacted:

```auto
cat /opt/mattermost/config/config.json | grep -A29 "EmailSettings"

```

Also, are you getting those errors you listed when you click on the **Test Connection** button based on the combination of SMTP Server Port and Connection Security?

---

<div class="post-metadata">

**Author:** ![djangofan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/djangofan/32/3650_2.png) [@djangofan](https://forum.mattermost.com/u/djangofan)\
**Post date:** [June 20, 2020, 12:30am UTC](https://forum.mattermost.com/t/tls-connection-error-sendmail-tls-first-record-does-not-look-like-a-tls-handshake/7283/8 "2020-06-20T00:30:23Z")

</div>

Thank you @ahmaddanial

I finally figured out how to solve it.

1. My “Route 53” DNS record needed to be re-validated (via the SES settings) so that the corrrect DKIM entries (3 of them) were added to my DNS record. That , in combination with me using a AWS SES validated email was the first half of the trick.
2. Secondly, I needed to edit /opt/mattermost/config/config.json and add ReplyToAddress , FeedbackEmail, and FeedbackName. values (which my host DigitalOcean forgot to add for me)

Thank you. Happy to have it working.

---

<div class="post-metadata">

**Author:** ![ahmaddanial](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/ahmaddanial/32/2938_2.png) [@ahmaddanial](https://forum.mattermost.com/u/ahmaddanial)\
**Post date:** [June 21, 2020, 11:06pm UTC](https://forum.mattermost.com/t/tls-connection-error-sendmail-tls-first-record-does-not-look-like-a-tls-handshake/7283/9 "2020-06-21T23:06:01Z")

</div>

Hi, @djangofan

Excellent. Thank you for sharing the solution you performed on your end!

---

<div class="post-metadata">

**Author:** ![mksa](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@mksa](https://forum.mattermost.com/u/mksa)\
**Post date:** [May 27, 2024, 10:26am UTC](https://forum.mattermost.com/t/tls-connection-error-sendmail-tls-first-record-does-not-look-like-a-tls-handshake/7283/10 "2024-05-27T10:26:19Z")

</div>

I’m getting the same error message. Here are the settings:

- SMTP Server: `smtp.mailersend.net`
- SMTP Server Port: `587`
- Enable SMTP Authentication: `true`
- SMTP Server Username: `<my username>`
- SMTP Server Password: `<my password>`
- Connection Security: `TLS (Recommended)`
- Skip Server Certificate Verification: `false`
- Enable Security Alerts: `true`

Log event:

```auto
{
  "caller": "web/context.go:115",
  "err_where": "testEmail",
  "error": "testEmail: Connection unsuccessful: unable to connect to the SMTP server through TLS: tls: first record does not look like a TLS handshake",
  "http_code": 500,
  "ip_addr": "172.18.0.4",
  "level": "error",
  "method": "POST",
  "msg": "Connection unsuccessful: unable to connect to the SMTP server through TLS: tls: first record does not look like a TLS handshake",
  "path": "/api/v4/email/test",
  "request_id": "ziqfkwsfqp8ruxbbg9y6r3hb4e",
  "timestamp": "2024-05-27 10:03:37.666 Z",
  "user_id": "ezhhwcbtdiy13cyktd3qgy5xaa"
}

```

My SMTP server is okay because I have other services using it and it works fine.  
I also checked the ReplyToAddress, FeedbackEmail and FeedbackName values which are set properly.
