-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsending_logs_to_mail.py
33 lines (29 loc) · 1.12 KB
/
sending_logs_to_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
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def SendEmail(message, to, From, password, subject):
msg = MIMEMultipart()
msg['From'] = From
msg['To'] = to
msg['Subject'] = subject
msg.attach(MIMEText(message, 'plain'))
server = smtplib.SMTP('smtp.gmail.com: 587')
server.starttls()
server.login(From, password)
text = msg.as_string()
server.sendmail(From, to, text)
server.quit()
#Hello - the body, if its from a print, remove "".
#"[email protected]" - reciever
#"[email protected]" - sender
#"password" - pss of the sender (must have less secure app permissions ON, 2FA disabled)
#"Subject" - subject of the mail
SendEmail("Hello", "[email protected]", "[email protected]", "password", "Subject")
#if function returns a string
SendEmail(GetLatencyFunction(), "[email protected]", "[email protected]", "password", "Subject")
# Code Block, if using exceptions
EXAMPLE:
except Exception as e:
print(f"exception {e} occurred")
SendEmail(e, "[email protected]", "[email protected]", "password", "Subject")
quit() # Better to exit if you are using generalized Exceptions though.