我试图用html模板从django发送电子邮件。它确实发送电子邮件,但是html是以纯文本的形式发送的。如何使电子邮件在接收方中显示为html?
我在用Django 4.0
views.py
# import file with html content
html_version = 'activate_email.html'
html_message = render_to_string(html_version, {'context': context })
email = EmailMessage(
'Website email verification',
html_message,
'info@example.co',
[user.email],
)
email.send()
activate_email.html
{% autoescape off %}
<h1>Test</h1>
{% endautoescape %}
发布于 2021-12-28 15:11:51
您可以在content_subtype
类上使用更高级的EmailMessage属性来更改主要内容。
email = EmailMessage(
'Website email verification',
html_message,
'info@example.co',
[user.email],
)
email.content_subtype = "html" # Main content is now text/html
email.send()
https://stackoverflow.com/questions/70508460
复制相似问题