views.py
if 'send_email' in request.POST:
subject, from_email, to = 'Parent Incident Notification',user.email, person.parent_email
html_content = render_to_string('incident/print.html',{'person':person,
'report':report,
})
text_content = strip_tags(html_content)
msg = EmailMultiAlternatives(subject, text_content, settings.DEFAULT_FROM_EMAIL, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()
以上是发送电子邮件的视图。通过这种方式,我可以发送html内容和邮件,它发送电子邮件到[地址]单独,我想再制作另一个密送和cc。我经历过docs.I中的Emailmessage objects
我不知道如何包含bcc和cc来改变我的观点。
需要帮助。
由于
答案 0 :(得分:26)
EmailMultiAlternatives
是EmailMessage
的子类。初始化消息时,您可以指定bcc
和cc
。
msg = EmailMultiAlternatives(subject, text_content, from_email, [to_email], bcc=[bcc_email], cc=[cc_email])
答案 1 :(得分:5)
EmailMessage
现在支持cc
和bcc
:
https://docs.djangoproject.com/en/1.10/topics/email/#django.core.mail.EmailMessage
答案 2 :(得分:1)
我需要以HTML内容作为正文的密件抄送,这是我的实现方式
from django.core.mail import EmailMessage
email = EmailMessage(
'Subject',
'htmlBody',
'from@email.com',
[to@email.com],
[bcc@email.com],
reply_to=['reply_to@email.com']
)
email.content_subtype = "html"
email.send(fail_silently=True)
有关更多详细信息,请参见Django docs