且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

django+ 使用 django-registration 以 html 格式发送电子邮件

更新时间:2023-12-02 09:03:22

我建议同时发送文本版本和 html 版本.在 django-registration 的 models.py 中查找:

I'd recommend sending both a text version and an html version. Look in the models.py of the django-registration for :

send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [self.user.email])

而是从文档中执行类似操作 http://docs.djangoproject.com/en/dev/topics/email/#sending-alternative-content-types

and instead do something like from the docs http://docs.djangoproject.com/en/dev/topics/email/#sending-alternative-content-types

from django.core.mail import EmailMultiAlternatives

subject, from_email, to = 'hello', 'from@example.com', 'to@example.com'
text_content = 'This is an important message.'
html_content = '<p>This is an <strong>important</strong> message.</p>'
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()