Files
TheGrapefruitsDuo/server/app/admin/contact.py
2024-05-05 13:32:31 -07:00

24 lines
665 B
Python

import smtplib
from email.mime.text import MIMEText
from os import getenv
from app.constants import HOST
def send_email(subject: str, body: str) -> None:
"""
Sends an email using the Gmail SMTP server.
:param str subject: The subject of the email
:param str body: The body of the email
"""
password = getenv("APP_PASSWORD")
email = getenv("EMAIL")
msg = MIMEText(body)
msg["Subject"] = subject
msg["From"] = HOST
smtp_server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
smtp_server.login(HOST, password) # type: ignore
smtp_server.sendmail(HOST, [email], msg.as_string()) # type: ignore
smtp_server.quit()