aboutsummaryrefslogtreecommitdiff
path: root/gn_auth
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-08-21 04:41:46 -0500
committerFrederick Muriuki Muriithi2024-08-21 04:41:46 -0500
commitdf2b0262f2678f642729ed1e5066744246b53b19 (patch)
tree7c3b89b7ead71ad98c007ae53c51c894e8e916ca /gn_auth
parente4286d9f04619030054b5a6425b059b783c6d87c (diff)
downloadgn-auth-df2b0262f2678f642729ed1e5066744246b53b19.tar.gz
Use username and password, when present, during sending emails
If the username and password are provided, make use of them to send emails out.
Diffstat (limited to 'gn_auth')
-rw-r--r--gn_auth/smtp.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/gn_auth/smtp.py b/gn_auth/smtp.py
index 9dc0e5f..2f0e7f4 100644
--- a/gn_auth/smtp.py
+++ b/gn_auth/smtp.py
@@ -41,8 +41,8 @@ def build_email_message(# pylint: disable=[too-many-arguments]
def send_message(# pylint: disable=[too-many-arguments]
- smtp_user: str,# pylint: disable=[unused-argument]
- smtp_passwd: str,# pylint: disable=[unused-argument]
+ smtp_user: str,
+ smtp_passwd: str,
message: EmailMessage,
host: str = "",
port: int = 587,
@@ -54,4 +54,8 @@ def send_message(# pylint: disable=[too-many-arguments]
logging.debug("Email to send:\n******\n%s\n******\n", message.as_string())
with smtplib.SMTP(host, port, local_hostname, timeout, source_address) as conn:
conn.ehlo()
+ if bool(smtp_user) and bool(smtp_passwd):
+ conn.starttls()
+ conn.login(smtp_user, smtp_passwd)
+
conn.send_message(message)