在django发送电子邮件到bcc和cc [英] send email to bcc and cc in django

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

问题描述

views.py

 如果请求中发送'send_email'.POST:
subject,from_email,to ='父事件通知',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。我通过文件中的 Emailmessage对象我不知道如何包含bcc和cc来改变我的观点。



需要帮助。



谢谢

解决方案

EmailMultiAlternatives EmailMessage 。您可以在初始化邮件时指定 bcc cc

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

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()

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.

Need help.

Thanks

解决方案

EmailMultiAlternatives is a subclass of EmailMessage. You can specify bcc and cc when you initialise the message.

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆