From 12e5e72015d9fc67cc84bbc464497c3d59c4356e Mon Sep 17 00:00:00 2001 From: fazledyn-or Date: Mon, 20 Nov 2023 13:56:38 +0600 Subject: [PATCH 1/2] Added `SMTP_SSL` option with authentication Signed-off-by: fazledyn-or --- .../common/src/python/mediawords/util/mail.py | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/apps/common/src/python/mediawords/util/mail.py b/apps/common/src/python/mediawords/util/mail.py index 9bea5ec1ed..f463896cf1 100644 --- a/apps/common/src/python/mediawords/util/mail.py +++ b/apps/common/src/python/mediawords/util/mail.py @@ -134,11 +134,22 @@ def send_email(message: Message) -> bool: else: - # Connect to SMTP - smtp = smtplib.SMTP( - host=CommonConfig.smtp().hostname(), - port=CommonConfig.smtp().port(), - ) + # Connect to SMTP_SSL + if CommonConfig.smtp().use_starttls(): + smtp = smtplib.SMTP_SSL( + host=CommonConfig.smtp().hostname(), + port=CommonConfig.smtp().port(), + ) + smtp.login( + user=CommonConfig.smtp().username(), + password=CommonConfig.smtp().password(), + ) + else: + # Connect to SMTP + smtp = smtplib.SMTP( + host=CommonConfig.smtp().hostname(), + port=CommonConfig.smtp().port(), + ) # Send message refused_recipients = smtp.sendmail(mime_message['From'], mime_message['To'], mime_message.as_string()) From 902ed59e2029cc5c442d72714e118f2eb104a241 Mon Sep 17 00:00:00 2001 From: fazledyn-or Date: Mon, 20 Nov 2023 13:56:47 +0600 Subject: [PATCH 2/2] Removed FIXME tag for SMTP Signed-off-by: fazledyn-or --- apps/common/src/python/mediawords/util/config/common.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/common/src/python/mediawords/util/config/common.py b/apps/common/src/python/mediawords/util/config/common.py index c0f117393c..e85098f5b6 100644 --- a/apps/common/src/python/mediawords/util/config/common.py +++ b/apps/common/src/python/mediawords/util/config/common.py @@ -274,13 +274,11 @@ def port() -> int: @staticmethod def use_starttls() -> bool: """Use STARTTLS? If you enable that, you probably want to change the port to 587.""" - # FIXME remove altogether, not used return False @staticmethod def username() -> str: """Username.""" - # FIXME remove, not used return '' @staticmethod