Private
Public Access
1
0

first use of email templates

This commit is contained in:
Sander Roosendaal
2018-03-18 20:15:48 +01:00
parent 4d962d4f52
commit 240210d43e
4 changed files with 44 additions and 13 deletions

View File

@@ -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

View 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>

View File

@@ -0,0 +1,5 @@
Dear {{ first_name }},
Please find attached the requested file for your workout.
Best Regards, the Rowsandall Team

View File

@@ -7,6 +7,7 @@ from django.conf import settings
import uuid
import datetime
lbstoN = 4.44822
landingpages = (