我尝试使用带有 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()
答案 0 :(得分:7)
要显示Name
而不是电子邮件的用户名部分,请执行
from_email = "info@domain.com <info@domain.com>"
OR
from_email = "Name <info@domain.com>"