-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendMail.py
36 lines (25 loc) · 943 Bytes
/
sendMail.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
import smtplib
import json
from email.message import EmailMessage
def send_mail(
BODY: str,
):
with open("../../env.json", "r") as f:
env = json.load(f)
HOST = env["HOST"] # smtp domain of the email provider
PORT = env["PORT"] # smtp port of the email provider
msg = EmailMessage()
msg["Subject"] = "Connection Request from Homepage Form"
msg["From"] = env["FROM_EMAIL"]
msg["To"] = ", ".join(env["TO_EMAIL"])
msg.set_content(str(BODY))
server = smtplib.SMTP(HOST, PORT)
status_code, response = server.ehlo()
print(f"[*] EHLO: {status_code}, {response}")
status_code, response = server.starttls()
print(f"[*] STARTTLS: {status_code}, {response}")
status_code, response = server.login(env["FROM_EMAIL"], env["PW"])
print(f"[*] LOGIN: {status_code}, {response}")
response = server.send_message(msg)
print(f"[*] SENDMAIL: {response}")
server.quit()