-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemailhtmlexcel.py
37 lines (35 loc) · 1.04 KB
/
emailhtmlexcel.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
import smtplib
import config
import xlrd
import email.message
li=[]
# Give the location of the file
loc = ("a.xls")
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
sheet.cell_value(0, 0)
for i in range(sheet.nrows):
print(sheet.cell_value(i, 0))
li.append(sheet.cell_value(i, 0))
print(li)
for i in range(len(li)):
print('a')
try:
print('b')
email_content = """<html> <head></head><body><h1>HOw are you</body></h1></html>"""
msg = email.message.Message()
msg['Subject'] = 'Tutsplus Newsletter'
msg['From'] = config.EMAIL_ADDRESS
msg['To'] = li[i]
password = config.PASSWORD
msg.add_header('Content-Type', 'text/html')
msg.set_payload(email_content)
s = smtplib.SMTP('smtp.gmail.com: 587')
s.starttls()
#message="wow"
s.login(msg['From'], password)
s.sendmail(msg['From'], [msg['To']], msg.as_string())
#s.quit()
print("Email Sent")
except :
print("Email failed to send.")