Email could not initiate SMTP session error

Under Gitea 1.17, I had the email configured as such:

[mailer]
ENABLED = true
HOST        = mail.mydomain.com:587
FROM        = GitAdmin <git@mydomain.com>
USER         = myaccount@mydomain.com
PASSWD   = 'mypassword'
PROTOCOL = smtps
SMTP_ADDR = mail.mydomain.com
SMTP_PORT  = 587

and it worked. I was able to send email. Now, I’ve installed version 1.21.0 and I’m trying to configure the email. As HOST is being deprecated, I have this:

[mailer]
ENABLED = true
FROM        = GitAdmin <git@mydomain.com>
USER         = myaccount@mydomain.com
PASSWD   = 'mypassword'
PROTOCOL = smtps
SMTP_ADDR = mail.mydomain.com
SMTP_PORT  = 587

But, it doesn’t work! When I attempt to send a test email from the configuration page, I’m getting the error “could not initiate SMTP session: tls: first record does not look like a TLS handshake”.

This is what is in the documentation at Email setup | Gitea Documentation

Any body have any ideas?

The docs appear to be inconsistent. They list PROTOCOL = smtps in conjunction with SMTP _PORT = 587, but the submission daemon that listens on TCP 587 is normally configured for STARTTLS.

You might try setting PROTOCOL = starttls and see if that works. Alternately, you could switch to SMTP _PORT = 465 which uses implicit TLS.

Thanks for the reply. Unfortunately, I get authentication failed in both cases. The message is:

Failed to send a testing email to “xxx@somedomain.com”: gomail: could not send email 1: failed to authenticate SMTP: 535 5.7.8 Error: authentication failed:

When I looked at the log on the mail server, in both cases, the log entry is “SASL PLAIN authentication failed:”

And I doubled checked – the user name and password specified in the app.ini configuration file are correct.

You may want to manually test from the host with Gitea.

Thanks for the link.

Anyway, using the instructions in the link you provided, I was able to successfully connect and send test emails using both ports 465 and 587.

So the problem isn’t with making an email connection from the computer running Gitea. Which seems to bring us back to the problem being an issue with Gitea itself. (Hopefully it’s just a configuration issue and not some bug.)

FYI (and for anyone else reading this thread), the example statement on that link for connecting to port 465 is incorrect. It should just be:
openssl s_client -connect example.com:465
not as shown:
openssl s_client -starttls smtp -connect example.com:465
because for port 465 SSL is implicit.

1 Like