-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.py
65 lines (30 loc) · 1.21 KB
/
mail.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
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
import pandas
from datetime import datetime
class mail(object):
#_____________________________________________________________________________
def __init__(self):
self.login_file = "login.csv"
self.subscribers_file = "subscribers.csv"
#_____________________________________________________________________________
def put_msg(self, msg_text):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
login = pandas.read_csv(self.login_file)
server.login(login["login"][0], login["pwd"][0])
msg_time = ", time: " + str(datetime.now()).split(".")[0]
msg_text += msg_time
maillist = pandas.read_csv(self.subscribers_file)
for imail in range(len(maillist)):
msg = MIMEMultipart()
sendfrom = login["login"][0]
sendto = maillist["address"][imail]
msg['From'] = sendfrom
msg['To'] = sendto
msg['Subject'] = "STAR Alarm Handler"
msg.attach(MIMEText(msg_text, 'plain'))
server.sendmail(sendfrom, sendto, msg.as_string())
print msg_text
server.quit()