From 6bd765a0c078599b3e1482a578920336daa770a8 Mon Sep 17 00:00:00 2001 From: Brage <40792825+Terbau@users.noreply.github.com> Date: Mon, 6 Feb 2023 20:58:48 +0100 Subject: [PATCH] Fix dotkom possible duplicate address in error mail (#2989) --- utils/email.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/utils/email.py b/utils/email.py index 5df29386a..182edc071 100644 --- a/utils/email.py +++ b/utils/email.py @@ -21,6 +21,11 @@ def handle_mail_error( ) -> None: """Callback called when an error occures while sending batched emails.""" + dotkom_address = "dotkom@online.ntnu.no" + bcc = None + if to is not None and dotkom_address not in to: + bcc = [dotkom_address] + not_sent_recipients = list( itertools.chain.from_iterable(em.recipients() for em in emails_not_sent) ) @@ -48,11 +53,11 @@ def handle_mail_error( body=message, from_email="onlineweb4-error@online.ntnu.no", # TODO: Change?? to=to or [], - bcc=["dotkom@online.ntnu.no"], + bcc=bcc, ) email.send() - logger.info(f"Sent error email to {', '.join(to or [])} and dotkom@online.ntnu.no") + logger.info(f"Sent error email to {', '.join((to or []) + (bcc or []))}") class AutoChunkedEmailMessage: