Skip to content
Snippets Groups Projects
Verified Commit b4d08a21 authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

add STARTTLS support in mailer service

parent adf4af61
Branches
Tags
1 merge request!161Feature/add mailer service
......@@ -2,6 +2,7 @@
import smtplib
from email.message import EmailMessage
from ssl import create_default_context
from gso.settings import load_oss_params
......@@ -9,6 +10,8 @@ from gso.settings import load_oss_params
def send_mail(recipient, subject, body) -> None:
"""Send an email message to the given address.
Only supports STARTTLS, not SSL.
:param recipient: The destination address.
:param subject: The email subject.
:param body: The contents of the email message.
......@@ -21,6 +24,9 @@ def send_mail(recipient, subject, body) -> None:
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 or email_params.smtp_password:
s.login(email_params.smtp_username, email_params.smtp_password)
s.send_message(msg)
......@@ -159,6 +159,7 @@ class EmailParams(BaseSettings):
from_address: str
smtp_host: str
smtp_port: int
starttls_enabled: bool
smtp_username: str | None = ""
smtp_password: str | None = ""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment