-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathEmailAlert.py
More file actions
60 lines (52 loc) · 1.96 KB
/
EmailAlert.py
File metadata and controls
60 lines (52 loc) · 1.96 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
"""
Quick functions to alert on errors with script
change login creds to your own and change to/from email addresses
"""
def Py2send_email(SUBJECT, TEXT, HTML):
import smtplib, ssl
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
sender_email = "" # Enter your address
receiver_email = "" # Enter receiver address
msg = MIMEMultipart('alternative')
msg['Subject'] = SUBJECT
msg['From'] = sender_email
msg['To'] = receiver_email
# message = 'Subject: {}\n\n{}'.format(SUBJECT, TEXT)
port = 465 # For SSL
text = TEXT
html = HTML
# Create a secure SSL context
# Record the MIME types of both parts - text/plain and text/html.
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html.encode("utf8"), 'html')
msg.attach(part1)
msg.attach(part2)
context = ssl.create_default_context()
server=smtplib.SMTP_SSL("smtp.gmail.com", port)
server.login("", "") #Emaillogin,password
server.sendmail(sender_email, receiver_email, msg.as_string())
def Py3send_email(SUBJECT, TEXT, HTML):
import smtplib, ssl
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
sender_email = "" # Enter your address
receiver_email = "" # Enter receiver address
msg = MIMEMultipart('alternative')
msg['Subject'] = SUBJECT
msg['From'] = sender_email
msg['To'] = receiver_email
# message = 'Subject: {}\n\n{}'.format(SUBJECT, TEXT)
port = 465 # For SSL
text = TEXT
html = HTML
# Create a secure SSL context
# Record the MIME types of both parts - text/plain and text/html.
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
msg.attach(part1)
msg.attach(part2)
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", port, context=context) as server:
server.login("", "")
server.sendmail(sender_email, receiver_email, msg.as_string())