From df2b0262f2678f642729ed1e5066744246b53b19 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 21 Aug 2024 04:41:46 -0500 Subject: Use username and password, when present, during sending emails If the username and password are provided, make use of them to send emails out. --- gn_auth/smtp.py | 8 ++++++-- 1 file 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) -- cgit v1.2.3