-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemailsender.py
More file actions
27 lines (22 loc) · 771 Bytes
/
emailsender.py
File metadata and controls
27 lines (22 loc) · 771 Bytes
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
from smtplib import SMTP
import csv
gmail = 'admin@example.com'
password = 'yourpassword'
message = open('message.txt', mode='r').read()
message1 = str(message)
with open('ok - Sheet1.csv') as file:
reader = csv.reader(file)
next(reader)
for Name, Email in reader:
mailto = Email
subject = 'This is testing mail.'
msg1 = 'Dear ' + Name + '\n' + message1
msg = 'subject: {}\n\n {}'.format(subject, msg1)
mailServer = SMTP('smtp.gmail.com', 587)
mailServer.starttls()
mailServer.login(gmail, password)
print('sending email to'+mailto+'\n')
mailServer.sendmail(gmail, mailto, msg.encode('utf-8'))
print('\n successfully sent to '+mailto)
mailServer.quit()
file.close()