-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalert.py
More file actions
28 lines (23 loc) · 770 Bytes
/
alert.py
File metadata and controls
28 lines (23 loc) · 770 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
27
28
from smtplib import SMTP
from email.message import EmailMessage
class Alert:
def email_alert(subject, body, to):
# gmail account
user = "email-address"
password = "app based password"
# mail message init
msg = EmailMessage()
msg.set_content(body)
msg['subject'] = subject
msg['to'] = to
msg['from'] = user
# mail server init
server = SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(user, password)
# send defined message and close mail server connection
try:
server.sendmail(user, to, msg.as_string())
finally:
print("message was send to " + to + " with content: " + body)
server.quit()