-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
66 lines (45 loc) · 1.92 KB
/
main.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
from datetime import datetime
import xlrd
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
now = datetime.now()
month = int(str(now.month))
date = int(str(now.day))
loc = ("birthday.xlsx")
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
sheet.cell_value(0, 0)
for i in range(1,sheet.nrows):
if int(sheet.cell_value(i, 2)) == month :
if int(sheet.cell_value(i, 1)) == date :
mail = sheet.cell_value(i, 3)
name = sheet.cell_value(i, 0)
fromaddr = "sendermail"
toaddr = mail
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Happy BirthDay "
body = "A million wishes are flooding your timelines and private message box, but mine is merely telling you to live a much more eventful life because you have given me so many sweet memories to look back. I know how lucky I am to have you as my friend because people with good hearts as yours don’t come by all the time. Happy birthday, my friend." ;
msg.attach(MIMEText(body, 'plain'))
filename = "happy.jpg"
attachment = open("happy.jpg", "rb")
part = MIMEBase('application', 'octet-stream')
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', "attachment; filename= %s" % filename)
msg.attach(part)
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, "sender_password")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
print("done")
else:
continue
else:
continue