Django-allauth无法发送HTML邮件。

16
我在模板文件夹中添加了以下子文件夹和文件,以便覆盖电子邮件消息(根据文档https://github.com/pennersr/django-allauth#sending-e-mail)a):
templates/
   account/
     email/
       email_confirmation_message.html
       email_confirmation_message.txt
       email_confirmation_subject.txt

覆盖对于邮件的*.txt版本完美运作(我认为这意味着我有正确的文件夹结构),但我的问题是HTML版本未被django_allauth发送过去。


你使用的是哪个版本(HTML 邮件是 0.10+)?否则,我建议你逐步检查这段代码:https://github.com/pennersr/django-allauth/blob/052e500965f1e9913c51587f6d9f115ccb3bb21d/allauth/account/adapter.py#L67,看看为什么事情没有被捕获 - 你的目录结构看起来很好。 - pennersr
我正在使用版本0.11.1。我已经阅读了源代码,但不是非常彻底。我会再次阅读的。谢谢。 - Matthieu
好的,原来涉及到的源代码确实是以下内容: https://github.com/pennersr/django-allauth/blob/052e500965f1e9913c51587f6d9f115ccb3bb21d/allauth/account/models.py#L120仔细阅读文档后,我发现django_allauth在处理电子邮件注册消息时并没有提到新注册用户和老用户之间的区别。我将继续我的测试,我想我需要六个模板(email_confirmation_signup* and email_confirmation*)。 - Matthieu
好的,我已经弄清楚了整件事情。现在很清晰和简单。昨天真的很累,没有足够的注意力。 对我来说不清楚的是,在我的测试中发送了我重写的email_confirmation_message.txt版本(而不是源版本email_confirmation_signup_message.txt)。 - Matthieu
1个回答

26

对于遇到相同问题的人:

当涉及到电子邮件确认时,django_allauth会检查它是否为新用户,并相应地查找模板:

因此,您将需要覆盖:

email_confirmation_message.txt
email_confirmation_signup_message.txt

并添加HTML版本

email_confirmation_message.html
email_confirmation_signup_message.html

4
另外,我需要在文件“email_confirmation_signup_message.html”中更改文件扩展名为“.html”:{% include "account/email/email_confirmation_message.html" %} - reinaldoluckman
关于 {{ user }} 和 {{ confirmation link }},我如何将它们添加到自定义模板中? - Dominic M.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接