diff --git a/rowers/tasks.py b/rowers/tasks.py index 42568a6e..98e3c3d5 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -6,6 +6,7 @@ import gzip import shutil import numpy as np + from scipy import optimize import rowingdata @@ -40,7 +41,13 @@ from rowers.dataprepnodjango import ( create_c2_stroke_data_db ) -from django.core.mail import send_mail, EmailMessage + +from django.core.mail import ( + send_mail, + EmailMessage,EmailMultiAlternatives, + ) +from django.template.loader import get_template +from django.template import Context from django.db.utils import OperationalError import datautils @@ -51,7 +58,7 @@ import arrow # testing task - +from django.contrib.staticfiles import finders @app.task def add(x, y): @@ -625,24 +632,28 @@ def handle_sendemailcsv(first_name, last_name, email, csvfile,**kwargs): # send email with attachment fullemail = first_name + " " + last_name + " " + "<" + email + ">" subject = "File from Rowsandall.com" - message = "Dear " + first_name + ",\n\n" - message += "Please find attached the requested file for your workout.\n\n" - message += "Best Regards, the Rowsandall Team" - - - email = EmailMessage(subject, message, - 'Rowsandall ', - [fullemail]) + plaintext = get_template('csvemail.txt') + htmly = get_template('csvemail.html') + + d = {'first_name':first_name} + + from_email = 'Rowsandall ' + + text_content = plaintext.render(d) + html_content = htmly.render(d) + + msg = EmailMultiAlternatives(subject, text_content, from_email, [fullemail]) + msg.attach_alternative(html_content, "text/html") if os.path.isfile(csvfile): - email.attach_file(csvfile) + msg.attach_file(csvfile) else: csvfile2 = csvfile with gzip.open(csvfile + '.gz', 'rb') as f_in, open(csvfile2, 'wb') as f_out: shutil.copyfileobj(f_in, f_out) - email.attach_file(csvfile2) + msg.attach_file(csvfile2) os.remove(csvfile2) @@ -652,7 +663,7 @@ def handle_sendemailcsv(first_name, last_name, email, csvfile,**kwargs): emailbounced = False if not emailbounced: - res = email.send() + res = msg.send() return 1 diff --git a/rowers/templates/csvemail.html b/rowers/templates/csvemail.html new file mode 100644 index 00000000..95d44006 --- /dev/null +++ b/rowers/templates/csvemail.html @@ -0,0 +1,14 @@ + + + +

Dear {{ first_name }},

+ +

+ Please find attached the requested file for your workout. +

+ +

+ Best Regards, the Rowsandall Team +

+ + diff --git a/rowers/templates/csvemail.txt b/rowers/templates/csvemail.txt new file mode 100644 index 00000000..33071ef7 --- /dev/null +++ b/rowers/templates/csvemail.txt @@ -0,0 +1,5 @@ +Dear {{ first_name }}, + +Please find attached the requested file for your workout. + +Best Regards, the Rowsandall Team diff --git a/rowers/utils.py b/rowers/utils.py index e1588ffe..fa159aba 100644 --- a/rowers/utils.py +++ b/rowers/utils.py @@ -7,6 +7,7 @@ from django.conf import settings import uuid import datetime + lbstoN = 4.44822 landingpages = (