-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendemail.py
84 lines (72 loc) · 2.58 KB
/
sendemail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import email
import smtplib
import os
from config import *
scriptDir = os.path.dirname(__file__)
default = {
'firstName':'Foo',
'lastName':'Bar',
'email':'foo@bar.com',
'product':'ACME Part',
'link':'https://morris.glyndwr.io',
'salesperson':'Ben Fedoruk',
'orderNo':'55634',
'backETA':'idk',
'shipETA':'idk',
}
def readTemplate(template):
if template == 'request':
relPath = "Email Templates/online_payment_request.html"
elif template == 'backordered':
relPath = "Email Templates/special_order_backordered.html"
elif template == 'notAvailable':
relPath = "Email Templates/special_order_not_available.html"
elif template == 'ordered':
relPath = "Email Templates/special_order_ordered.html"
elif template == 'received':
relPath = "Email Templates/special_order_recieved.html"
else:
return
with open(os.path.join(scriptDir, relPath), 'r') as html:
data = html.read()
return data
def sendEmail(template, info=default):
msg_header = ('From: Revolution Cycle <onlinestore@revolutioncycle.com>\n'
'To: '+info['firstName']+" "+info['lastName']+' <'+info['email']+'>'
'MIME-Version: 1.0\n'
'Content-type: text/html\n'
'Subject: Online Payment Request from Revolution Cycle\n')
title = 'Hello '+info['firstName']
msg_content = readTemplate(template)
if msg_content == None:
return
msg_content = msg_content.replace('[CUSTOMER FIRST NAME]', info['firstName'])
msg_content = msg_content.replace('[PRODUCT NAME HERE]', info['product'])
msg_content = msg_content.replace('[SALESPERSON]', info['salesperson'])
msg_content = msg_content.replace('[PRODUCT LINK]', info['link'])
msg_content = msg_content.replace('[ORDER NUMBER]', str(info['orderNo']))
msg = (''.join([msg_header, msg_content])).encode()
server = smtplib.SMTP_SSL('mail.hover.com', 465) #
server.ehlo()
#server.starttls()
server.ehlo()
server.login(emailConfig['username'], emailConfig['password'])
server.sendmail(emailConfig['username'], info['email'], msg)
server.quit()
def isEmail(email):
try:
str(email)
atIndex = 0
dotIndex = 0
for i in range(len(email)):
if email[i] == '@':
atIndex = i
elif email[i] == '.':
dotIndex = i
if dotIndex == 0 or atIndex == 0:
return False
elif dotIndex < atIndex:
return False
return True
except:
return False