From 2b4b1d2f76dd6a6f8ac8f2d0bdcd138098346ef3 Mon Sep 17 00:00:00 2001 From: Jens L Date: Fri, 27 Oct 2023 00:39:06 +0200 Subject: [PATCH] stages/email: fix sending emails from task (#7325) closes #7322 Signed-off-by: Jens Langhammer --- authentik/stages/email/tasks.py | 5 +++++ authentik/stages/email/utils.py | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/authentik/stages/email/tasks.py b/authentik/stages/email/tasks.py index 02011d7f7..6f0b6e104 100644 --- a/authentik/stages/email/tasks.py +++ b/authentik/stages/email/tasks.py @@ -13,6 +13,7 @@ from authentik.events.models import Event, EventAction from authentik.events.monitored_tasks import MonitoredTask, TaskResult, TaskResultStatus from authentik.root.celery import CELERY_APP from authentik.stages.email.models import EmailStage +from authentik.stages.email.utils import logo_data LOGGER = get_logger() @@ -81,6 +82,10 @@ def send_mail(self: MonitoredTask, message: dict[Any, Any], email_stage_pk: Opti # Because we use the Message-ID as UID for the task, manually assign it message_object.extra_headers["Message-ID"] = message_id + # Add the logo (we can't add it in the previous message since MIMEImage + # can't be converted to json) + message_object.attach(logo_data()) + LOGGER.debug("Sending mail", to=message_object.to) backend.send_messages([message_object]) Event.new( diff --git a/authentik/stages/email/utils.py b/authentik/stages/email/utils.py index 5b2637662..a6edd4609 100644 --- a/authentik/stages/email/utils.py +++ b/authentik/stages/email/utils.py @@ -9,7 +9,7 @@ from django.utils import translation @lru_cache() -def logo_data(): +def logo_data() -> MIMEImage: """Get logo as MIME Image for emails""" path = Path("web/icons/icon_left_brand.png") if not path.exists(): @@ -29,5 +29,4 @@ class TemplateEmailMessage(EmailMultiAlternatives): super().__init__(**kwargs) self.content_subtype = "html" self.mixed_subtype = "related" - self.attach(logo_data()) self.attach_alternative(html_content, "text/html")