diff --git a/backend/app/api/notifications.py b/backend/app/api/notifications.py index 36ef944..4a82963 100644 --- a/backend/app/api/notifications.py +++ b/backend/app/api/notifications.py @@ -216,8 +216,13 @@ async def test_email( msg["From"] = from_addr msg["To"] = email_addr - with smtplib.SMTP(app_settings.SMTP_HOST, app_settings.SMTP_PORT, timeout=10) as s: - if app_settings.SMTP_STARTTLS: + use_ssl = app_settings.SMTP_PORT == 465 + if use_ssl: + ctx = smtplib.SMTP_SSL(app_settings.SMTP_HOST, app_settings.SMTP_PORT, timeout=10) + else: + ctx = smtplib.SMTP(app_settings.SMTP_HOST, app_settings.SMTP_PORT, timeout=10) + with ctx as s: + if not use_ssl and app_settings.SMTP_STARTTLS: s.starttls() if app_settings.SMTP_USER: s.login(app_settings.SMTP_USER, app_settings.SMTP_PASSWORD) diff --git a/backend/app/workers/notification_dispatcher.py b/backend/app/workers/notification_dispatcher.py index 5209dcd..de9d7dc 100644 --- a/backend/app/workers/notification_dispatcher.py +++ b/backend/app/workers/notification_dispatcher.py @@ -339,8 +339,13 @@ def _send_email( msg["List-Unsubscribe-Post"] = "List-Unsubscribe=One-Click" msg.attach(MIMEText(body, "plain", "utf-8")) - with smtplib.SMTP(app_settings.SMTP_HOST, app_settings.SMTP_PORT, timeout=10) as s: - if app_settings.SMTP_STARTTLS: + use_ssl = app_settings.SMTP_PORT == 465 + if use_ssl: + smtp_ctx = smtplib.SMTP_SSL(app_settings.SMTP_HOST, app_settings.SMTP_PORT, timeout=10) + else: + smtp_ctx = smtplib.SMTP(app_settings.SMTP_HOST, app_settings.SMTP_PORT, timeout=10) + with smtp_ctx as s: + if not use_ssl and app_settings.SMTP_STARTTLS: s.starttls() if app_settings.SMTP_USER: s.login(app_settings.SMTP_USER, app_settings.SMTP_PASSWORD)