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")