From 880c34a6ab5ed6b00700028129bc9d63822f617f Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Fri, 3 Feb 2023 16:05:47 +0100 Subject: [PATCH] feat(chalice): changed smtp helper --- api/chalicelib/utils/smtp.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api/chalicelib/utils/smtp.py b/api/chalicelib/utils/smtp.py index 63e1621fb..1fb80af76 100644 --- a/api/chalicelib/utils/smtp.py +++ b/api/chalicelib/utils/smtp.py @@ -17,20 +17,20 @@ class SMTPClient: def __init__(self): if config("EMAIL_HOST") is None or len(config("EMAIL_HOST")) == 0: return - elif config("EMAIL_USE_SSL").lower() == "false": - self.server = smtplib.SMTP(host=config("EMAIL_HOST"), port=int(config("EMAIL_PORT"))) + elif not config("EMAIL_USE_SSL", cast=bool): + self.server = smtplib.SMTP(host=config("EMAIL_HOST"), port=config("EMAIL_PORT", cast=int)) else: if len(config("EMAIL_SSL_KEY")) == 0 or len(config("EMAIL_SSL_CERT")) == 0: - self.server = smtplib.SMTP_SSL(host=config("EMAIL_HOST"), port=int(config("EMAIL_PORT"))) + self.server = smtplib.SMTP_SSL(host=config("EMAIL_HOST"), port=config("EMAIL_PORT", cast=int)) else: - self.server = smtplib.SMTP_SSL(host=config("EMAIL_HOST"), port=int(config("EMAIL_PORT")), + self.server = smtplib.SMTP_SSL(host=config("EMAIL_HOST"), port=config("EMAIL_PORT", cast=int), keyfile=config("EMAIL_SSL_KEY"), certfile=config("EMAIL_SSL_CERT")) def __enter__(self): if self.server is None: return EmptySMTP() self.server.ehlo() - if config("EMAIL_USE_SSL").lower() == "false" and config("EMAIL_USE_TLS").lower() == "true": + if not config("EMAIL_USE_SSL", cast=bool) and config("EMAIL_USE_TLS", cast=bool): self.server.starttls() # stmplib docs recommend calling ehlo() before & after starttls() self.server.ehlo()