From 1fc917bdf5ee36e78b6b2c7ce5667b90590505dd Mon Sep 17 00:00:00 2001 From: Stefan Bethke Date: Sat, 25 May 2024 12:21:29 +0200 Subject: [PATCH] Report SMTP error with more info --- hedgedoc-expire.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/hedgedoc-expire.py b/hedgedoc-expire.py index 195933f..5119535 100644 --- a/hedgedoc-expire.py +++ b/hedgedoc-expire.py @@ -60,11 +60,18 @@ class EmailSender: :param message: to be sent :return: """ - smtp_server = smtplib.SMTP(self.hostname, port=self.port) - context = ssl.create_default_context() - smtp_server.starttls(context=context) - smtp_server.login(self.username, self.password) - smtp_server.send_message(message) + try: + smtp_server = smtplib.SMTP(self.hostname, port=self.port) + context = ssl.create_default_context() + smtp_server.starttls(context=context) + smtp_server.login(self.username, self.password) + smtp_server.send_message(message) + except Exception as e: + print(f'Unable to send mail through {self}: {e}') + raise e + + def __str__(self): + return f'EmailSender<{self.hostname},{self.port},{self.username},{self.mail_from}>' class HedgedocExpire: