首页 > 解决方案 > 在 django send_mass_mail 发送的邮件中创建粗体文本

问题描述

Djangosend_mass_mail不允许发送 HTML 邮件,但我想将部分邮件加粗。

我试过了:

    message= ("bla bla  '<b>%s</b>'."% title.title)

但正如您可以猜到的那样,它会避开邮件中的标签。我想知道是否有解决方案。

标签: pythondjangoemailsendmail

解决方案


使用EmailMultiAlternatives

from django.core.mail import EmailMultiAlternatives

subject, from_email = 'hello', 'from@example.com'
text_content = 'plain text body message.'
html_content = '<p>This is an <strong>alternative</strong> message using HTML.</p>'
msg = EmailMultiAlternatives(subject, text_content, from_email, ['jhon@example.com', 'doe@example.com'])

msg.attach_alternative(html_content, "text/html")
msg.send()

这个答案也可以提供帮助。


推荐阅读