Newer
Older
"""The mailer service sends notification emails, as part of workflows that require interaction with external parties."""
import smtplib
from email.message import EmailMessage
from gso.settings import load_oss_params
def send_mail(recipient, subject, body) -> None:
"""Send an email message to the given address.
:param recipient: The destination address.
:param subject: The email subject.
:param body: The contents of the email message.
"""
email_params = load_oss_params().EMAIL
msg = EmailMessage()
msg["From"] = email_params.from_address
msg["To"] = recipient
msg["Subject"] = subject
msg.set_content(body)
with smtplib.SMTP(email_params.smtp_host, email_params.smtp_port) as s:
if email_params.smtp_username or email_params.smtp_password:
s.login(email_params.smtp_username, email_params.smtp_password)
s.send_message(msg)