azukaar / Cosmos-Server

☁️ The Most Secure and Easy Selfhosted Home Server. Take control of your data and privacy without sacrificing security and stability (Authentication, anti-DDOS, anti-bot)
https://cosmos-cloud.io
Other
3.65k stars 130 forks source link

[BUG]: Email SMTP SSL is not working with port 465 #351

Open sebmalissard opened 1 week ago

sebmalissard commented 1 week ago

What happened?

I enabled SMTP in the general configuration with the instructions provided by my hosting provider https://www.infomaniak.com/fr/support/faq/2427/synchroniser-les-e-mails-sur-tous-vos-appareils.

So I set:

But the server nerver send any email and the login to cosmos server is very slow (timeout wait)

What should have happened?

The cosmos server should by able to sent email and the login should not be slower.

How to reproduce the bug?

  1. Enable SMTP
  2. Configure SMTP with port 465
  3. Go in cosmos-ui/config-users
  4. Send an user password reset

Relevant log output

In server log I have:
2024/11/12 20:10:36 [ERROR] UserInvite: Error while sending email : EOF
2024/11/12 20:10:36 [ERROR] Request Timeout. Cancelling. : context deadline exceeded
2024/11/12 20:10:36 [ERROR] HTTP Request returned Error 504 : Gateway Timeout :

Other details

I did a quick analysis, and what I understand is that the issue is in the send email function: https://github.com/azukaar/Cosmos-Server/blob/master/src/utils/emails.go#L89.

Port 465 is reserved for SMTPS, and the connection should start encrypted directly. So, I think that if the UseTLS option is enabled and the port is 465, the function tls.Dial+smtp.NewClient should be used instead of smtp.Dial+config.EmailConfig.UseTLS.

System details