除了设置“HTTPS”环境变量和 SECURE_PROXY_SSL_HEADER
SECURE_SSL_REDIRECT,当在adapter.py render_mail() 中使用.txt 正文时,在渲染模板和使用EmailMultiAlternatives() 发送邮件时似乎也可能出现问题
[1]:https://github.com/pennersr/django-allauth/blob/master/allauth/account/adapter.py
for ext in ["html", "txt"]:
try:
template_name = "{0}_message.{1}".format(template_prefix, ext)
bodies[ext] = render_to_string(
template_name,
context,
self.request,
).strip()
except TemplateDoesNotExist:
if ext == "txt" and not bodies:
# We need at least one body
raise
if "txt" in bodies:
msg = EmailMultiAlternatives(subject, bodies["txt"], from_email, to)
if "html" in bodies:
msg.attach_alternative(bodies["html"], "text/html")
else:
msg = EmailMessage(subject, bodies["html"], from_email, to)
msg.content_subtype = "html" # Main content is now text/html
return msg
例如 print(bodies[ext]) 给出:
"To confirm this is correct, go to " https://127.0.0.1:8000/accounts/confirm-email/MjI:1kS0Mj:M5YfUf9-1Vg_TlgjVrK6vAtaLDE/ "
但在电子邮件上仍然是 http://
http://url7514.sitename/ls/click?upn=HJL2SSWV...
对于大多数设备,这也有效,因为仍应重定向到 https://,但在某些设备上没有,因此必须将默认模板/帐户/电子邮件/email_confirmation_message.txt 更改为 html 扩展名,
结果之后:
To confirm this is correct, go to https://sitename/accounts/confirm-email/M...