first use of email templates
This commit is contained in:
@@ -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 <info@rowsandall.com>',
|
||||
[fullemail])
|
||||
plaintext = get_template('csvemail.txt')
|
||||
htmly = get_template('csvemail.html')
|
||||
|
||||
d = {'first_name':first_name}
|
||||
|
||||
from_email = 'Rowsandall <info@rowsandall.com>'
|
||||
|
||||
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
|
||||
|
||||
14
rowers/templates/csvemail.html
Normal file
14
rowers/templates/csvemail.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<html>
|
||||
<body>
|
||||
<img src="https://rowsandall.com/static/img/logo7.png" height="50"</img>
|
||||
<p>Dear <strong>{{ first_name }}</strong>,</p>
|
||||
|
||||
<p>
|
||||
Please find attached the requested file for your workout.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Best Regards, the Rowsandall Team
|
||||
</p>
|
||||
|
||||
</body>
|
||||
5
rowers/templates/csvemail.txt
Normal file
5
rowers/templates/csvemail.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
Dear {{ first_name }},
|
||||
|
||||
Please find attached the requested file for your workout.
|
||||
|
||||
Best Regards, the Rowsandall Team
|
||||
@@ -7,6 +7,7 @@ from django.conf import settings
|
||||
import uuid
|
||||
import datetime
|
||||
|
||||
|
||||
lbstoN = 4.44822
|
||||
|
||||
landingpages = (
|
||||
|
||||
Reference in New Issue
Block a user