-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.py
33 lines (28 loc) · 1000 Bytes
/
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
import smtplib, ssl
from secret import MAIL
from logFile import Status_Report
def send_update(subject,Emessage):
port = MAIL.get('PORT') # For starttls
smtp_server = MAIL.get('SERVER')
sender_email = MAIL.get('EMAIL')
receiver_email =MAIL.get('EMAIL_TO')
password = MAIL.get('PASSWORD')
message = """\
Subject: {0}
{1}.""".format(subject,Emessage)
try:
context = ssl.create_default_context()
with smtplib.SMTP(smtp_server, port) as server:
server.ehlo() # Can be omitted
server.starttls(context=context)
server.ehlo() # Can be omitted
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message)
code="Mail Server Success"
Rmessage = "Email sent"
Status_Report(code,Rmessage)
except BaseException as error:
print(error)
code="Mail Server Error"
message = error
Status_Report(code,message)