stages/email: fix sending emails from task (#7325)
closes #7322 Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
parent
2ce5c74f33
commit
2b4b1d2f76
|
@ -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(
|
||||
|
|
|
@ -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")
|
||||
|
|
Reference in a new issue