diff --git a/gso/oss-params-example.json b/gso/oss-params-example.json index 18dc4b67f5442f336de85bb8c23f9827f7f2f2f7..902659e9cf40f866edd1fc58e7a0624748d82829 100644 --- a/gso/oss-params-example.json +++ b/gso/oss-params-example.json @@ -90,7 +90,8 @@ "smtp_port": 487, "starttls_enabled": true, "smtp_username": "username", - "smtp_password": "password" + "smtp_password": "password", + "notification_email_destinations": "oc@nren.local, neteng@nren.local, ceo@nren.local" }, "SHAREPOINT": { "client_id": "UUID", diff --git a/gso/services/mailer.py b/gso/services/mailer.py index 3cd85b7369fd176d55d02674f9b55e2c02a47a72..760d4c76c4fb25c6e5e4344b784bd8db82e88a9e 100644 --- a/gso/services/mailer.py +++ b/gso/services/mailer.py @@ -7,19 +7,19 @@ from ssl import create_default_context from gso.settings import load_oss_params -def send_mail(recipient: str, subject: str, body: str) -> None: - """Send an email message to the given address. +def send_mail(recipients: str, subject: str, body: str) -> None: + """Send an email message to the given addresses. Only supports STARTTLS, not SSL. - :param str recipient: The destination address. + :param str recipients: The destination addresses, comma separated. :param str subject: The email subject. :param str 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["To"] = recipients msg["Subject"] = subject msg.set_content(body) diff --git a/gso/settings.py b/gso/settings.py index 47720f1db83fda119e5fd6eea943b25d50403653..07f7bbdd5e802436de20219d76af611ff2b3d24a 100644 --- a/gso/settings.py +++ b/gso/settings.py @@ -11,12 +11,13 @@ import os from pathlib import Path from typing import Annotated -from pydantic import Field +from pydantic import EmailStr, Field from pydantic_forms.types import UUIDstr from pydantic_settings import BaseSettings from typing_extensions import Doc from gso.products.product_blocks.site import SiteTier +from gso.utils.shared_enums import PortNumber logger = logging.getLogger(__name__) @@ -152,13 +153,15 @@ class NetBoxParams(BaseSettings): class EmailParams(BaseSettings): """Parameters for the email service.""" - # TODO: Use more strict types after we've migrated to Pydantic 2.x - from_address: str + from_address: EmailStr smtp_host: str - smtp_port: int + smtp_port: PortNumber starttls_enabled: bool smtp_username: str | None = None smtp_password: str | None = None + #: List of email addresses that should receive notifications when validation of a subscription fails. + #: Can be a comma-separated list of multiple addresses. + notification_email_destinations: str class SharepointParams(BaseSettings):