-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmail.py
More file actions
32 lines (27 loc) · 899 Bytes
/
mail.py
File metadata and controls
32 lines (27 loc) · 899 Bytes
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
import config
smtp_server = "smtp.mail.ru"
port = 587 # For starttls
sender_email = config.email
password = config.email_password
def send_email(errors):
# Create a secure SSL context
context = ssl.create_default_context()
# Try to log in to server and send email
try:
server = smtplib.SMTP(smtp_server, port)
server.ehlo() # Can be omitted
server.starttls(context=context) # Secure the connection
server.ehlo() # Can be omitted
server.login(sender_email, password)
# TODO: Send email here
text = "\n".join(errors)
email = f"""\
Subject: Error occured while parcing from https://www.adac.de/
{text}"""
server.sendmail(sender_email, config.receiver_email, email)
except Exception as e:
# Print any error messages to stdout
print(e)
finally:
server.quit()