Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send email to bcc and cc in 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()

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

like image 516
user2086641 Avatar asked Jun 12 '13 11:06

user2086641


2 Answers

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])
like image 112
Alasdair Avatar answered Sep 28 '22 09:09

Alasdair


EmailMessage now supports cc and bcc:

https://docs.djangoproject.com/en/1.10/topics/email/#django.core.mail.EmailMessage

like image 45
TopRamenGod Avatar answered Sep 28 '22 09:09

TopRamenGod