-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmail.py
28 lines (17 loc) · 780 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
from email.message import EmailMessage
import ssl
import smtplib
def send_email(cont_dic, mail_receiver):
mail_sender = '[email protected]'
mail_password = 'wakmwxfbaikayjcs'
subject = 'Complaint Register'
body = f"Potholes are identifed at location: {cont_dic['location']}. It's a {cont_dic['highway_type']} that contains {cont_dic['size']}. Take necessary actions"
em = EmailMessage()
em['From'] = mail_sender
em['To'] = mail_receiver
em['subject'] = subject
em.set_content(body)
context = ssl.create_default_context()
with smtplib.SMTP_SSL('smtp.gmail.com', 465, context=context) as smtp:
smtp.login(mail_sender, mail_password)
smtp.sendmail(mail_sender, mail_receiver, em.as_string())