在Django send_mass_mail发送的邮件中创建粗体文本

2024-05-06 08:57:31 发布

您现在位置:Python中文网/ 问答频道 /正文

Django的send_mass_mail不允许发送HTML邮件,但我想将邮件的一部分加粗

我试过:

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

但正如你所猜测的,它在邮件中逃过了标签。我想知道是否有解决办法


Tags: djangosendmessagetitlehtml邮件mail标签
1条回答
网友
1楼 · 发布于 2024-05-06 08:57:31

使用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也有帮助

相关问题 更多 >