-
Notifications
You must be signed in to change notification settings - Fork 0
/
emailer.py
118 lines (91 loc) · 2.91 KB
/
emailer.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import smtplib
import csv
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# me == my email address
# you == recipient's email address
me = "[email protected]"
with open('saidsacontacts.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
print row['EMAIL']
# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "YOUR COMPANY SERVICE"
msg['From'] = me
msg['To'] = row['EMAIL']
html = """\
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width">
<title>YOUR COMPANY</title>
<style>
body {
width: 100% !important;
min-width: 100%;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
margin: 0;
Margin: 0;
padding: 0;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box; }
</style>
</head>
<body>
<img src="LINK TO SOME IMAGE">
<p>Dear Sirs, <br></p>
<p>Please may I have a moment of your time to explain our service.<br></p>
<p>Please do not hesitate to <a href="mailto:[email protected]">contact us</a> should you have any queries</p>
<p>Sincerely Yours,<br><br></p>
<h5>SALES CONSULTANT</h5>
<p>Sales Manager<br>
company name<br>
Phone: 555 319 1088<br>
Mobile: 555 738 4038<br>
Email: <a href="mailto:[email protected]">[email protected]</a></p>
</body>
</html>
"""
# Record the MIME types of both parts - text/plain and text/html.
content = MIMEText(html, 'html')
# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
#msg.attach(part1)
msg.attach(content)
gmail_user = '[email protected]'
gmail_password = 'yourpassword'
try:
#server = smtplib.SMTP('smtp.gmail.com:587')
server = smtplib.SMTP(host ='smtp.gmail.com', port='587')
#server_ssl = smtplib.SMTP_SSL('smtp.gmail.com', '465')
print 'host =smtp.gmail.com, port=587'
server.ehlo()
print 'ehlo'
server.starttls()
print 'starttls'
server.login(gmail_user, gmail_password)
print 'Logged in'
server.sendmail(me, row['EMAIL'], msg.as_string())
print 'sent'
server.quit()
print 'successfully sent the mail'
line = []
line.append(row['COMPANY'])
line.append(row['EMAIL'])
line.append('Successful')
with open("emailerreport.csv", "a") as fp:
wr = csv.writer(fp, dialect='excel')
wr.writerow(line)
except:
print "failed to send mail"
line = []
line.append(row['EMAIL'])
line.append('Failed')
with open("emailerreport.csv", "a") as fp:
wr = csv.writer(fp, dialect='excel')
wr.writerow(line)