Skip to content

Mailer

The mailer service sends notification emails, as part of workflows that require interaction with external parties.

send_mail(subject, body)

Send an email message to the given addresses.

Only supports STARTTLS, not SSL.

Parameters:

Name Type Description Default
subject str

The email subject.

required
body str

The contents of the email message.

required
Source code in gso/services/mailer.py
def send_mail(subject: str, body: str) -> None:
    """Send an email message to the given addresses.

    Only supports STARTTLS, not SSL.

    Args:
        subject: The email subject.
        body: The contents of the email message.
    """
    email_params = load_oss_params().EMAIL
    msg = EmailMessage()
    msg["From"] = email_params.from_address
    msg["To"] = email_params.notification_email_destinations
    msg["Subject"] = subject
    msg.set_content(body)

    with smtplib.SMTP(email_params.smtp_host, email_params.smtp_port) as s:
        if email_params.starttls_enabled:
            tls_context = create_default_context()
            s.starttls(context=tls_context)
        if email_params.smtp_username and email_params.smtp_password:
            s.login(email_params.smtp_username, email_params.smtp_password)
        s.send_message(msg)