-
Notifications
You must be signed in to change notification settings - Fork 0
/
alerts.py
48 lines (40 loc) · 1.41 KB
/
alerts.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
#Send warning alerts and notify throguh mail
#libraries
from tkinter import *
from tkinter import ttk
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
def warning_message():
#Create an instance of tkinter frame
win = Tk()
#Set the geometry of tkinter frame
win.geometry("750x270")
win.title("WARNING")
Label(win, text= "--Insert warning message to be displayed",font=('Helvetica 18 bold')).pack(pady=40)
#Automatically close the window after 3 seconds
win.after(2000,lambda:win.destroy())
win.mainloop()
#send email
def send_mail(filename,snap_num):
fromaddr = "--From address"
toaddr = "--To address"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "--Subject of mail"
body = "--Body of mail "+str(snap_num)+"."
msg.attach(MIMEText(body, 'plain'))
attachment = open(filename, "rb")
p = MIMEBase('application', 'octet-stream')
p.set_payload((attachment).read())
encoders.encode_base64(p)
p.add_header('Content-Disposition', "attachment; filename= %s" % filename)
msg.attach(p)
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login(fromaddr, "--Password")
text = msg.as_string()
s.sendmail(fromaddr, toaddr, text)