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

could you send me your config file? I’m also facing the same issue while setting up email for gitea.

Unfortunately, I’ve never been able to get Gitea to actually successfully send an email. So, what I have in my configuration for emails probably won’t help you any.

All that I’ve been able to do was to manually send an email using openssl s_client to demonstrate that the issue (as far as I can tell) is with Gitea, and not the mail server.

FYI, I’m still running 1.21.0. I haven’t upgraded to 1.21.4 yet.

Sorry that I am not able to really help you. If you do managed to get email to work, I would love to hear how you managed to do so.

Sure. If I manage to do that… :rofl:

Hi, got it working with setting FROM with same entry as USER as mail.

Thomas,

Would you mind posting an example of your configuration showing the email related settings?

Hi, these are my mailer settings:

[mailer]
ENABLED = true
FROM = "Gitea Admin" <part1.part2@web.de>
SMTP_ADDR = smtp.web.de
SMTP_PORT = 465
USER = part1.part2@web.de
PASSWD = `passwd`

So what did the trick was, setting FROM in <> equal to USER and PASSWD in ``

Hope, that helps

1 Like

Thank you tomekk. I was finally able to get email to work!

But, I did encounter a problem when the password contained certain special characters. A number of special characters are fine. But, when the password contained either a pound (#) or semicolon (:wink: character, I got an authorization error.

I was specifying the password like this:

PASSWD = ‘password#’

Here’s a list of the specials characters that I’ve tried using and worked:

& ! _ ? = ( ) { } @ $

(I used the password generator from LastPass to generate a random password and specified to also include special characters.)

1 Like

If anyone finds this page that’s trying to configure mail on Gitea or Forgejo with Postmark, then try the configuration I’m sharing. The problem that I had was that I couldn’t use port 587 on Akamai/Linode.

Looks like there’s a blog post about it: https://www.linode.com/blog/linode/a-new-policy-to-help-fight-spam/

When I ran a Netcat command on my server:

nc -zv smtp.postmarkapp.com 587

it hanged, so I also tried:

nc -zv smtp.postmarkapp.com 2525

then, the connection succeeded.

My working configuration using Postmark is:

[mailer]
ENABLED = true
SMTP_ADDR = smtp.postmarkapp.com
SMTP_PORT = 2525
PROTOCOL = smtp+starttls
FROM = "Forgejo Admin" <git@myemailaddress.com>
USER = Server API token here
PASSWD = Server API token here as well

Remember to restart the service. In my case:

systemctl restart forgejo.service