From f1e313dbeec1a091b9dfb35bb7da19bf08276f4c Mon Sep 17 00:00:00 2001
From: Karel van Klink <karel.vanklink@geant.org>
Date: Wed, 24 Jul 2024 13:15:33 +0200
Subject: [PATCH] Add mail recipient to oss params

---
 gso/oss-params-example.json |  3 ++-
 gso/services/mailer.py      |  8 ++++----
 gso/settings.py             | 11 +++++++----
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/gso/oss-params-example.json b/gso/oss-params-example.json
index 18dc4b67..902659e9 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 3cd85b73..760d4c76 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 47720f1d..07f7bbdd 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):
-- 
GitLab