only login to SMTP server, if username and password set

This commit is contained in:
Julian Schacher 2024-12-09 15:15:13 +01:00
parent 48ba4ef7ca
commit 1911694baf

View file

@ -64,6 +64,7 @@ class EmailSender:
smtp_server = smtplib.SMTP(self.hostname, port=self.port) smtp_server = smtplib.SMTP(self.hostname, port=self.port)
context = ssl.create_default_context() context = ssl.create_default_context()
smtp_server.starttls(context=context) smtp_server.starttls(context=context)
if self.username != "" and self.password != "":
smtp_server.login(self.username, self.password) smtp_server.login(self.username, self.password)
smtp_server.send_message(message) smtp_server.send_message(message)
except Exception as e: except Exception as e: