Exception handling and logging for SMTP errors

Should mitigate internal server errors if SMTP server fails.
This commit is contained in:
2022-08-19 12:07:38 +01:00
parent f132cdbeef
commit 1c57950558
2 changed files with 24 additions and 10 deletions

View File

@@ -6,6 +6,7 @@ from .test import Test
from flask_login import current_user
from flask_mail import Message
from smtplib import SMTPException
from datetime import datetime, timedelta
from uuid import uuid4
@@ -174,4 +175,7 @@ class Entry(db.Model):
<p>Best wishes, <br/> SKA Refereeing</p>
"""
)
mail.send(email)
try:
mail.send(email)
except SMTPException as exception:
write('system.log', f'SMTP Error when trying to notify results to {self.get_surname()}, {self.get_first_name()} with error: {exception}')