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

add skeleton email service

parent 550e2a6e
No related branches found
No related tags found
1 merge request!161Feature/add mailer service
"""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)
......@@ -152,6 +152,17 @@ class NetBoxParams(BaseSettings):
api: str
class EmailParams(BaseSettings):
"""Parameters for the email service."""
# TODO: Use more strict types after we've migrated to Pydantic 2.x
from_address: str
smtp_host: str
smtp_port: int
smtp_username: str | None = ""
smtp_password: str | None = ""
class OSSParams(BaseSettings):
"""The set of parameters required for running :term:`GSO`."""
......@@ -162,6 +173,7 @@ class OSSParams(BaseSettings):
PROVISIONING_PROXY: ProvisioningProxyParams
CELERY: CeleryParams
THIRD_PARTY_API_KEYS: dict[str, str]
EMAIL: EmailParams
def load_oss_params() -> OSSParams:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment