使用EmailMultiAlternatives发送Django邮件
我正在用Django发送邮件,使用的是EmailMultiAlternatives。这个方法运行得很好,但在“发件人”那里只显示了“info”。
我能不能把我的名字显示出来,比如说我的名字?我该怎么做呢?
这是我的代码:
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()
1 个回答
8
如果你想在显示的时候用Name
来代替邮箱里的用户名部分,只需要这样做:
from_email = "info@domain.com <info@domain.com>"
或者
from_email = "Name <info@domain.com>"