python - 在 django send_mass_mail 发送的邮件中创建粗体文本
问题描述
Djangosend_mass_mail
不允许发送 HTML 邮件,但我想将部分邮件加粗。
我试过了:
message= ("bla bla '<b>%s</b>'."% title.title)
但正如您可以猜到的那样,它会避开邮件中的标签。我想知道是否有解决方案。
解决方案
使用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()
这个答案也可以提供帮助。
推荐阅读
- android - 找不到任何与 com.android.support:appcompat-v7:29.+ 匹配的版本
- python - 如何在 SciKit-Learn Python 中识别 KNN 模型中每个集群内的记录?
- flutter - 如何从 aync/await 函数返回布尔值并将其传递给其他页面中的其他变量
- ruby - 最新的 gem 版本未安装
- python - 如何在 Beam 中将单例 pvalue 输出到控制台?
- windows - 普通 Powershell 提示符中的工作命令在 PSSession 中拒绝访问
- stripe-payments - 如何将优惠券添加到 Stripe 的结账处
- hibernate - 在 jhipster 生成的应用程序中对实体执行 CRUD 操作时自动生成历史表
- solr - 将静态值传递给 Solr DIH 索引中的字段
- javascript - 将音频源转换为“一次性”blob