From 83cfb5f8c24619e255e11c047846a9c83bd70953 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 4 May 2021 18:30:23 +0200 Subject: [PATCH] stages/email: improve error handling Signed-off-by: Jens Langhammer --- authentik/stages/email/tasks.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/authentik/stages/email/tasks.py b/authentik/stages/email/tasks.py index 462f3dae6..517ae1a4d 100644 --- a/authentik/stages/email/tasks.py +++ b/authentik/stages/email/tasks.py @@ -48,7 +48,12 @@ def send_mail( stage: EmailStage = EmailStage(use_global_settings=True) else: stage: EmailStage = EmailStage.objects.get(pk=email_stage_pk) - backend = stage.backend + try: + backend = stage.backend + except ValueError as exc: + LOGGER.warning(exc) + self.set_status(TaskResult(TaskResultStatus.ERROR).with_error(exc)) + return backend.open() # Since django's EmailMessage objects are not JSON serialisable, # we need to rebuild them from a dict @@ -68,7 +73,7 @@ def send_mail( messages=["Successfully sent Mail."], ) ) - except (SMTPException, ConnectionError, ValueError) as exc: + except (SMTPException, ConnectionError) as exc: LOGGER.debug("Error sending email, retrying...", exc=exc) self.set_status(TaskResult(TaskResultStatus.ERROR).with_error(exc)) raise exc