From cbed58e0ca2b741ee371e80bf5a23c22c63f001d Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Sat, 20 Jun 2020 12:09:43 +0200 Subject: [PATCH] adding bcc --- rowers/emails.py | 19 +++++++++++++------ rowers/tasks.py | 4 ++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/rowers/emails.py b/rowers/emails.py index b232ee09..d3d76ff6 100644 --- a/rowers/emails.py +++ b/rowers/emails.py @@ -53,7 +53,7 @@ from django.contrib.staticfiles import finders def textify(html): - # Remove html tags and continuous whitespaces + # Remove html tags and continuous whitespaces text_only = re.sub('[ \t]+', ' ', strip_tags(html)) # Strip single spaces in the beginning of each line return text_only.replace('\n ', '\n').strip() @@ -61,7 +61,7 @@ def textify(html): def htmlstripnobr(html): safe_html = re.sub('[ \t]+', ' ', strip_tags(html)) return safe_html - + def htmlstrip(html): safe_html = re.sub('[ \t]+', ' ', strip_tags(html)) return newlinetobr(safe_html) @@ -80,11 +80,18 @@ def send_template_email(from_email,to_email,subject, text_content = textify(html_content) # html_content = newlinetobr(html_content) - if 'cc' in kwargs: + print(kwargs['bcc']) + + if 'bcc' in kwargs and 'cc' in kwargs: + msg = EmailMultiAlternatives(subject, text_content, from_email, to_email,cc=kwargs['cc'], + bcc=kwargs['bcc']) + elif 'bcc' in kwargs: + msg = EmailMultiAlternatives(subject, text_content, from_email, to_email,bcc=kwargs['bcc']) + elif 'cc' in kwargs: msg = EmailMultiAlternatives(subject, text_content, from_email, to_email,cc=kwargs['cc']) else: msg = EmailMultiAlternatives(subject, text_content, from_email, to_email) - + msg.attach_alternative(html_content, "text/html") if 'attach_file' in kwargs: @@ -106,8 +113,8 @@ def send_template_email(from_email,to_email,subject, else: emailbounced = False - - + + if not emailbounced: res = msg.send() else: diff --git a/rowers/tasks.py b/rowers/tasks.py index d0d5844b..f573ec44 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -2446,8 +2446,8 @@ def handle_send_template_email(template,email,fromemail,rowername, } res = send_template_email('Rowsandall ', - fullemail,subject, - template,d,cc=[fromemail],**kwargs) + ['info@rowsandall.com'],subject, + template,d,cc=[fromemail],bcc=fullemail,**kwargs) @app.task def handle_sendemail_message(email,fromemail,rowername,message,teamname,managername,