本文介绍了在 Django 中发送电子邮件到密件抄送和抄送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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内容与邮件一起发送,它将电子邮件单独发送到[to]地址,我还想制作另一个密件抄送和抄送.我经历了docs 中的 Emailmessage objects.我不知道如何包含 bcc 和 cc 来改变我的观点.

The above is the view to send email.By that way i can send the html content along with mail,it is sending the email to [to] address alone ,i want to made another bcc and cc also.I gone through the Emailmessage objects in docs.I don't know how to include the bcc and cc to alter my views.

需要帮助.

谢谢

推荐答案

EmailMultiAlternativesEmailMessage.您可以在初始化消息时指定 bcccc.

msg = EmailMultiAlternatives(subject, text_content, from_email, [to_email], bcc=[bcc_email], cc=[cc_email])

这篇关于在 Django 中发送电子邮件到密件抄送和抄送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 12:17