diff --git a/gso/oss-params-example.json b/gso/oss-params-example.json index 931367ea48746610b29646651e99a68f89d1288e..007b899bf956cca6cdf148d79001637d181b5939 100644 --- a/gso/oss-params-example.json +++ b/gso/oss-params-example.json @@ -77,5 +77,13 @@ "THIRD_PARTY_API_KEYS": { "AnsibleDynamicInventoryGenerator": "REALLY_random_AND_secure_T0keN", "Application_2": "another_REALY_random_AND_3cure_T0keN" + }, + "EMAIL": { + "from_address": "noreply@nren.local", + "smtp_host": "smtp.nren.local", + "smtp_port": 487, + "starttls_enabled": true, + "smtp_username": "username", + "smtp_password": "password" } } diff --git a/gso/services/mailer.py b/gso/services/mailer.py index ee4d7dd932e9608d5dd103887645cb04464838a5..3cd85b7369fd176d55d02674f9b55e2c02a47a72 100644 --- a/gso/services/mailer.py +++ b/gso/services/mailer.py @@ -7,14 +7,14 @@ from ssl import create_default_context from gso.settings import load_oss_params -def send_mail(recipient, subject, body) -> None: +def send_mail(recipient: str, subject: str, body: str) -> 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. + :param str recipient: The destination address. + :param str subject: The email subject. + :param str body: The contents of the email message. """ email_params = load_oss_params().EMAIL msg = EmailMessage() @@ -27,6 +27,6 @@ def send_mail(recipient, subject, body) -> None: 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: + if email_params.smtp_username and email_params.smtp_password: s.login(email_params.smtp_username, email_params.smtp_password) s.send_message(msg) diff --git a/gso/settings.py b/gso/settings.py index de22223844b0d814973b2ffac10244f4f4c28a8d..0189986d9cdf15c347393f2a55c1f23944922b36 100644 --- a/gso/settings.py +++ b/gso/settings.py @@ -160,8 +160,8 @@ class EmailParams(BaseSettings): smtp_host: str smtp_port: int starttls_enabled: bool - smtp_username: str | None = "" - smtp_password: str | None = "" + smtp_username: str | None + smtp_password: str | None class OSSParams(BaseSettings): diff --git a/test/conftest.py b/test/conftest.py index dd6e9d6d3fc3429f0ce0df33213de8dc1f195523..895b4798208a936c137ecd32358cd38cbeb42617 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -208,6 +208,14 @@ def configuration_data() -> dict: "AnsibleDynamicInventoryGenerator": "REALY_random_AND_3cure_T0keN", "Application_2": "another_REALY_random_AND_3cure_T0keN", }, + "EMAIL": { + "from_address": "noreply@nren.local", + "smtp_host": "smtp.nren.local", + "smtp_port": 487, + "starttls_enabled": True, + "smtp_username": "username", + "smtp_password": "password", + }, }