first use of email templates
This commit is contained in:
@@ -6,6 +6,7 @@ import gzip
|
|||||||
import shutil
|
import shutil
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
from scipy import optimize
|
from scipy import optimize
|
||||||
|
|
||||||
import rowingdata
|
import rowingdata
|
||||||
@@ -40,7 +41,13 @@ from rowers.dataprepnodjango import (
|
|||||||
create_c2_stroke_data_db
|
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
|
from django.db.utils import OperationalError
|
||||||
|
|
||||||
import datautils
|
import datautils
|
||||||
@@ -51,7 +58,7 @@ import arrow
|
|||||||
|
|
||||||
# testing task
|
# testing task
|
||||||
|
|
||||||
|
from django.contrib.staticfiles import finders
|
||||||
|
|
||||||
@app.task
|
@app.task
|
||||||
def add(x, y):
|
def add(x, y):
|
||||||
@@ -625,24 +632,28 @@ def handle_sendemailcsv(first_name, last_name, email, csvfile,**kwargs):
|
|||||||
# send email with attachment
|
# send email with attachment
|
||||||
fullemail = first_name + " " + last_name + " " + "<" + email + ">"
|
fullemail = first_name + " " + last_name + " " + "<" + email + ">"
|
||||||
subject = "File from Rowsandall.com"
|
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"
|
|
||||||
|
|
||||||
|
plaintext = get_template('csvemail.txt')
|
||||||
|
htmly = get_template('csvemail.html')
|
||||||
email = EmailMessage(subject, message,
|
|
||||||
'Rowsandall <info@rowsandall.com>',
|
d = {'first_name':first_name}
|
||||||
[fullemail])
|
|
||||||
|
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):
|
if os.path.isfile(csvfile):
|
||||||
email.attach_file(csvfile)
|
msg.attach_file(csvfile)
|
||||||
else:
|
else:
|
||||||
csvfile2 = csvfile
|
csvfile2 = csvfile
|
||||||
with gzip.open(csvfile + '.gz', 'rb') as f_in, open(csvfile2, 'wb') as f_out:
|
with gzip.open(csvfile + '.gz', 'rb') as f_in, open(csvfile2, 'wb') as f_out:
|
||||||
shutil.copyfileobj(f_in, f_out)
|
shutil.copyfileobj(f_in, f_out)
|
||||||
|
|
||||||
email.attach_file(csvfile2)
|
msg.attach_file(csvfile2)
|
||||||
os.remove(csvfile2)
|
os.remove(csvfile2)
|
||||||
|
|
||||||
|
|
||||||
@@ -652,7 +663,7 @@ def handle_sendemailcsv(first_name, last_name, email, csvfile,**kwargs):
|
|||||||
emailbounced = False
|
emailbounced = False
|
||||||
|
|
||||||
if not emailbounced:
|
if not emailbounced:
|
||||||
res = email.send()
|
res = msg.send()
|
||||||
|
|
||||||
|
|
||||||
return 1
|
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 uuid
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
lbstoN = 4.44822
|
lbstoN = 4.44822
|
||||||
|
|
||||||
landingpages = (
|
landingpages = (
|
||||||
|
|||||||
Reference in New Issue
Block a user