Leantime / leantime

Leantime is a goals focused project management system for non-project managers. Building with ADHD, Autism, and dyslexia in mind.
https://leantime.io
GNU Affero General Public License v3.0
4.41k stars 578 forks source link

[BUG] Incorrect Message on SMTP Errors #1795

Open ashhem opened 1 year ago

ashhem commented 1 year ago

What set up are you using Self Hosted hosted on shared hosting

Describe the bug The platform shows an success message incorrectly despite encountering an error in SMTP. So far, I have not been able to use the platform much I this is clearly reproducible in Invite User functionality. No errors are logged into the error.log too.

To Reproduce Steps to reproduce the behavior:

  1. Go to config/configuration.php
  2. Scroll to / Email / section
  3. Toggle $useSMTP setting to true
  4. Enter incorrect SMTP settings, in my case, I put wrong password for troubleshooting.
  5. Go to 'User Management'
  6. Click on Add User' & fill in the required details with a proper working email id.
  7. Scroll down to 'Invite User'
  8. See error

Expected behavior The toast should so message like "Could not invite user due to error in SMTP configuration [Error description here]". Example: "Could not invite user due to error in SMTP configuration [Authentication failed]". We can optionally skip the error description in the toast, however in any case, the error should be logged in the error.log file

Leantime Version 2.3.27

Server Apache

PHP / MySQL Version PHP Version: 8.0.29 MySQL Version: 10.4.30-MariaDB

Additional context As mentioned above, I am not sure if this error is happening across the platform wherever SMTP is being used since I have just started using the platform. I have so far come across this error on Invite User service only.

My (redacted) email settings are: / Email / public $email = 'email@mydomain';
public $useSMTP = true;
public $smtpHosts = 'smtp.mydomain';
public $smtpAuth = true;
public $smtpUsername = 'email@mydomain';
public $smtpPassword = 'myWRONGpassword'; public $smtpAutoTLS = false; public $smtpSecure = 'SSL';
public $smtpSSLNoverify = false; public $smtpPort = '465';

almereyda commented 10 months ago

We're seeing a similar error here, where inviting a user in the dashboard just keeps infinitely spinning, and requesting a password reset is confirmed, but not sent.

This is happening with validated configuration in all cases of TLS/465 SSL/465 STARTTLS/587 and AUTO_TLS true and false. There is no indication in the logs of the email server, that Leantime would be trying to contact it.

I've found a commit ff6aa68fb902caf839d9062e6c4fea583ca58fd5 that changed the way the environmental variables are interpolated. It may be all this is related to recent regressions with email, all from 2023:

Hosted:

There is email-related logging in the Docker container in the logs at stdout when LEAN_DEBUG=1 is set and a user is invited, spinning 20 seconds, until a modal with red text opens and says "An error occurred.". It doesn't show anything when requesting a password reset mail.

NOTICE: PHP message: 3 Connection: opening to email.ecobytes.net:465, timeout=20, options=array()
NOTICE: PHP message: 3 Connection: opened

When resending the invitation message, after having switched to 587/STARTTLS with AUTO_TLS=false, the email client is able to connect to the server, but not able to use the supplied credentials to authenticate. They were double checked and are confirmed to be working.

NOTICE: PHP message: 3 Connection: opening to email.ecobytes.net:587, timeout=20, options=array()
NOTICE: PHP message: 3 Connection: opened
NOTICE: PHP message: 4 SMTP INBOUND: "220 email.ecobytes.net ESMTP"
NOTICE: PHP message: 2 SERVER -> CLIENT: 220 email.ecobytes.net ESMTP
NOTICE: PHP message: 1 CLIENT -> SERVER: EHLO lean.allmende.io
NOTICE: PHP message: 4 SMTP INBOUND: "250-email.ecobytes.net"
NOTICE: PHP message: 4 SMTP INBOUND: "250-PIPELINING"
NOTICE: PHP message: 4 SMTP INBOUND: "250-SIZE 26214400"
NOTICE: PHP message: 4 SMTP INBOUND: "250-ETRN"
NOTICE: PHP message: 4 SMTP INBOUND: "250-STARTTLS"
NOTICE: PHP message: 4 SMTP INBOUND: "250-ENHANCEDSTATUSCODES"
NOTICE: PHP message: 4 SMTP INBOUND: "250-8BITMIME"
NOTICE: PHP message: 4 SMTP INBOUND: "250-DSN"
NOTICE: PHP message: 4 SMTP INBOUND: "250 CHUNKING"
NOTICE: PHP message: 2 SERVER -> CLIENT: 250-email.ecobytes.net
250-PIPELINING
250-SIZE 26214400
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250 CHUNKING
NOTICE: PHP message: 4 SMTP Error: Could not authenticate.
NOTICE: PHP message: 1 CLIENT -> SERVER: QUIT
NOTICE: PHP message: 4 SMTP INBOUND: "221 2.0.0 Bye"
NOTICE: PHP message: 2 SERVER -> CLIENT: 221 2.0.0 Bye
NOTICE: PHP message: 3 Connection: closed
NOTICE: PHP message: 4 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

In the logs of the email server I only get:

Nov 14 00:58:57 email postfix/submission/smtpd[3628464]: connect from geogale.ecobytes.net[88.99.144.132]
Nov 14 00:58:57 email postfix/submission/smtpd[3628464]: disconnect from geogale.ecobytes.net[88.99.144.132] ehlo=1 quit=1 commands=2

It appears something with the LEAN_EMAIL_SMTP_SECURE setting/function is not quite right: When using port 465 and enforcing TLS or SSL, nothing happens. When using port 587, which allows plain text connections, the initial connection attempt works, but is not upgraded to STARTTLS, why I suspect no authentication can happen.

Setting AUTO_TLS to true again made STARTTLS on port 587 work as expected. I don't know why this additional configuration toggle is needed, since every STARTTLS connection needs to send the STARTTLS command.