【问题标题】:creating bold text in mails sent by django send_mass_mail在 django send_mass_mail 发送的邮件中创建粗体文本
【发布时间】:2020-10-15 01:58:34
【问题描述】:
Django 的send_mass_mail 不允许发送 HTML 邮件,但我想将部分邮件加粗。
我试过了:
message= ("bla bla '<b>%s</b>'."% title.title)
但你可以猜到它会转义邮件中的标签。我想知道是否有解决方案。
【问题讨论】:
标签:
python
django
email
sendmail
【解决方案1】:
使用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()
This answer 也可以提供帮助。