Skip to content

Commit

Permalink
fix(account/adapter): Use TEMPLATE_EXTENSION when sending mail
Browse files Browse the repository at this point in the history
  • Loading branch information
pennersr committed Dec 15, 2023
1 parent a778398 commit fbb104a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions allauth/account/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ def render_mail(self, template_prefix, email, context, headers=None):
from_email = self.get_from_email()

bodies = {}
for ext in ["html", "txt"]:
html_ext = app_settings.TEMPLATE_EXTENSION
for ext in [html_ext, "txt"]:
try:
template_name = "{0}_message.{1}".format(template_prefix, ext)
bodies[ext] = render_to_string(
Expand All @@ -164,10 +165,12 @@ def render_mail(self, template_prefix, email, context, headers=None):
msg = EmailMultiAlternatives(
subject, bodies["txt"], from_email, to, headers=headers
)
if "html" in bodies:
msg.attach_alternative(bodies["html"], "text/html")
if html_ext in bodies:
msg.attach_alternative(bodies[html_ext], "text/html")
else:
msg = EmailMessage(subject, bodies["html"], from_email, to, headers=headers)
msg = EmailMessage(
subject, bodies[html_ext], from_email, to, headers=headers
)
msg.content_subtype = "html" # Main content is now text/html
return msg

Expand Down

0 comments on commit fbb104a

Please sign in to comment.