-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmailAlert.py
35 lines (29 loc) · 870 Bytes
/
EmailAlert.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
from email.message import EmailMessage
from configparser import ConfigParser
# Read config.ini file
config_object = ConfigParser()
config_object.read("config.ini")
# Get the creds
creds = config_object['password']
def email_alert(subject, body, to):
msg = EmailMessage()
msg.set_content(body)
msg['subject'] = subject
msg['to'] = to
#provide email and password
user = "[email protected]"
password = creds
msg['from'] = user
#create server
server = smtplib.SMTP("smtp.gmail.com", 587)
#server setting needed by gmail
server.starttls()
#login to server
server.login(user,password['password'])
#send msg
server.send_message(msg)
#close server conn
server.quit()
if __name__ == '__main__':
email_alert("Test", "Hello, sent using Python!", "[email protected]")