forked from awerks/se_project_1000
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
25 lines (21 loc) · 943 Bytes
/
utils.py
File metadata and controls
25 lines (21 loc) · 943 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
import smtplib
import os
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_email(to_address, subject, html_body):
smtp_server = os.environ.get("SMTP_SERVER")
smtp_port = int(os.environ.get("SMTP_PORT"))
smtp_username = os.environ.get("SMTP_USERNAME")
smtp_password = os.environ.get("SMTP_PASSWORD")
from_address = os.environ.get("SMTP_USERNAME")
message = MIMEMultipart("alternative")
message["Subject"] = subject
message["From"] = from_address
message["To"] = to_address
text_part = MIMEText("Please view this email in an HTML compatible client.", "plain")
html_part = MIMEText(html_body, "html")
message.attach(text_part)
message.attach(html_part)
with smtplib.SMTP_SSL(smtp_server, smtp_port, timeout=5) as server:
server.login(smtp_username, smtp_password)
server.sendmail(from_address, to_address, message.as_string())