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

Add mail recipient to oss params

parent 0408be41
No related branches found
No related tags found
1 merge request!239Feature/send validation emails
...@@ -90,7 +90,8 @@ ...@@ -90,7 +90,8 @@
"smtp_port": 487, "smtp_port": 487,
"starttls_enabled": true, "starttls_enabled": true,
"smtp_username": "username", "smtp_username": "username",
"smtp_password": "password" "smtp_password": "password",
"notification_email_destinations": "oc@nren.local, neteng@nren.local, ceo@nren.local"
}, },
"SHAREPOINT": { "SHAREPOINT": {
"client_id": "UUID", "client_id": "UUID",
......
...@@ -7,19 +7,19 @@ from ssl import create_default_context ...@@ -7,19 +7,19 @@ from ssl import create_default_context
from gso.settings import load_oss_params from gso.settings import load_oss_params
def send_mail(recipient: str, subject: str, body: str) -> None: def send_mail(recipients: str, subject: str, body: str) -> None:
"""Send an email message to the given address. """Send an email message to the given addresses.
Only supports STARTTLS, not SSL. 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 subject: The email subject.
:param str body: The contents of the email message. :param str body: The contents of the email message.
""" """
email_params = load_oss_params().EMAIL email_params = load_oss_params().EMAIL
msg = EmailMessage() msg = EmailMessage()
msg["From"] = email_params.from_address msg["From"] = email_params.from_address
msg["To"] = recipient msg["To"] = recipients
msg["Subject"] = subject msg["Subject"] = subject
msg.set_content(body) msg.set_content(body)
......
...@@ -11,12 +11,13 @@ import os ...@@ -11,12 +11,13 @@ import os
from pathlib import Path from pathlib import Path
from typing import Annotated from typing import Annotated
from pydantic import Field from pydantic import EmailStr, Field
from pydantic_forms.types import UUIDstr from pydantic_forms.types import UUIDstr
from pydantic_settings import BaseSettings from pydantic_settings import BaseSettings
from typing_extensions import Doc from typing_extensions import Doc
from gso.products.product_blocks.site import SiteTier from gso.products.product_blocks.site import SiteTier
from gso.utils.shared_enums import PortNumber
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -152,13 +153,15 @@ class NetBoxParams(BaseSettings): ...@@ -152,13 +153,15 @@ class NetBoxParams(BaseSettings):
class EmailParams(BaseSettings): class EmailParams(BaseSettings):
"""Parameters for the email service.""" """Parameters for the email service."""
# TODO: Use more strict types after we've migrated to Pydantic 2.x from_address: EmailStr
from_address: str
smtp_host: str smtp_host: str
smtp_port: int smtp_port: PortNumber
starttls_enabled: bool starttls_enabled: bool
smtp_username: str | None = None smtp_username: str | None = None
smtp_password: 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): class SharepointParams(BaseSettings):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment