forked from neelshah2409/Bot-Collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail_module.py
30 lines (22 loc) · 901 Bytes
/
email_module.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
import smtplib
from email.message import EmailMessage
# This program/method takes in a subject, body and recepient to send text and email notifications
# for additional context: https://www.youtube.com/watch?v=B1IsCbXp0uE
def email_alert(subject, body, to):
msg = EmailMessage()
msg.set_content(body)
msg['subject'] = subject
msg['to'] = to
# email created for this purpose and application password bypassing MFA
user = "insert email here"
password = "insert generated password here"
msg['from'] = user
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(user, password)
server.send_message(msg)
server.quit
# test 2 testing email and text message capabilities
if __name__ == '__main__':
email_alert("Hey","Test Email","receiver")
email_alert("Hey","Test Message","phone number@ cell provider receiver")