forked from guanquann/Stocksera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail_server.py
38 lines (29 loc) · 1010 Bytes
/
email_server.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
33
34
35
36
37
38
"""
Script for setting up email so that any suggestions or feedbacks will be sent to admin
"""
import os
import ssl
import yaml
import smtplib
from datetime import datetime
with open("config.yaml") as config_file:
config_keys = yaml.load(config_file, Loader=yaml.Loader)
def send_email_to_self(name, email, feedback):
port = 465
smtp_server = "smtp.gmail.com"
sender_email = config_keys["GMAIL_SENDER_EMAIL"]
password = config_keys["GMAIL_SENDER_PASSWORD"]
receiver_email = os.environ.get("EMAIL_RECEIVER") or "Enter receiver address"
message = f"""\
Subject: Feedback!
This message is sent from Stocksera Admin.
Name: {name}
Email: {email}
Feedback: {feedback}
Time Sent: {str(datetime.utcnow()).split(".")[0]} UTC
Thank you & have a nice day!
"""
context = ssl.create_default_context()
with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message)