diff --git a/rowers/tasks.py b/rowers/tasks.py index 6e882bcd..b3fed727 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -38,6 +38,29 @@ def textify(html): # Strip single spaces in the beginning of each line return text_only.replace('\n ', '\n').strip() +def send_template_email(from_email,to_email,subject,template,context,*args,**kwargs): + + htmly = get_template(template) + + html_content = htmly.render(context) + text_content = textify(html_content) + + msg = EmailMultiAlternatives(subject, text_content, from_email, to_email) + msg.attach_alternative(html_content, "text/html") + + + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = msg.send() + else: + return 0 + + return res + from utils import deserialize_list from rowers.dataprepnodjango import ( @@ -1096,21 +1119,7 @@ def handle_sendemailnewresponse(first_name, last_name, 'commentid':commentid } - html_content = htmly.render(d) - text_content = textify(html_content) - - msg = EmailMultiAlternatives(subject, text_content, from_email, [fullemail]) - msg.attach_alternative(html_content, "text/html") - - - if 'emailbounced' in kwargs: - emailbounced = kwargs['emailbounced'] - else: - emailbounced = False - - if not emailbounced: - res = msg.send() - + res = send_template_email(from_email,[fullemail],subject,'teamresponseemail.html',d,**kwargs) return 1