python - 使用 EmailMultiAlternatives 向 django 发送电子邮件

标签 python django email html-email mailing

我正在尝试使用带有 EmailMultiAlternatives 的 Django 发送邮件。它运作良好,但在“来自”中说“信息”

可以说出我的名字吗?我该怎么做?

这是我的代码:

subject, from_email, to = 'Afiliations', 'info@domain.com', 'other@domain.com'
text_content = 'Afiliation is working.'
t = loader.get_template('emails/afiliados.html')
c = Context({ 'order': order_obj })
html_content = t.render(c)
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()

最佳答案

要显示 Name 而不是电子邮件的用户名部分,只需执行以下操作

from_email = "info@domain.com <info@domain.com>"

from_email = "Name <info@domain.com>"

关于python - 使用 EmailMultiAlternatives 向 django 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25350849/

相关文章:

email - CakePHP 2.1.0 : Capture E-mail Output

python - 删除列标题中 : 之前的所有字符

python - 如何在 Y 时间内打印 X 数量的字符串?

Python + Selenium + PhantomJS 渲染为 PDF

python - 具有日期比较条件的非纳米值的 Pandas 数据框中的计数值

python - 如何在 gitlab-ci.yml 中将 postgis 扩展添加到 postgresql 数据库

django - Celery - 收到类型为 'core.tasks.scrape_dev_to' 的未注册任务

android - 邮件发送程序说明

python - 如何检索其中包含哈希的 GET 变量

php - 使用同步驱动程序在 Laravel 4 中排队电子邮件