Send an email to bcc and cc to 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 a representation for sending email. So that I can send the contents of html along with the mail, it sends an email to the address [to] one, I want to make another copy and cc as well. I went through Emailmessage objects in docs.I don't know how to enable bcc and cc to change my views.

Need help.

thanks

+12
source share
3 answers

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

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

I needed a blind carbon copy with HTML content as the body, and here is my implementation

 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) 

For more details see Django Docs

0
source

Source: https://habr.com/ru/post/947104/


All Articles