forked from dewanshrawat15/Mailing-Script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
55 lines (46 loc) · 1.5 KB
/
script.py
File metadata and controls
55 lines (46 loc) · 1.5 KB
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
SMTPserver = ''
sender = ''
USERNAME = ""
PASSWORD = ""
# typical values for text_subtype are plain, html, xml
subject="" # subject of the email
import sys
import os
import re
import csv
import time
from smtplib import SMTP_SSL as SMTP # this invokes the secure SMTP protocol (port 465, uses SSL)
# from smtplib import SMTP # use this for standard SMTP protocol (port 25, no encryption)
# old version
# from email.MIMEText import MIMEText
from email.mime.text import MIMEText
conn = SMTP(SMTPserver)
conn.set_debuglevel(False)
conn.login(USERNAME, PASSWORD)
with open('tbm.csv') as data:
row = csv.DictReader(data)
for line in row:
name = line['First Name']
add = line['Email']
text_subtype = 'html'
# content
content="""\
"""
msg = MIMEText(content, text_subtype)
try:
msg['Subject'] = subject
msg['From'] = sender # some SMTP servers will do this automatically, not all
# try:
conn.sendmail(sender, add, msg.as_string())
print('Mail sent to '+name+'')
except:
print('Output Sequence ended')
time.sleep(2)
print('SMTP secured')
time.sleep(2)
print('Terminating SMTP connection!')
time.sleep(1)
exit()
conn.quit()
# except:
# sys.exit( "mail failed; %s" % "CUSTOM_ERROR" ) # give an error message