diff --git a/backend/routes/outreach.py b/backend/routes/outreach.py index 4fbd03c..9b072dc 100644 --- a/backend/routes/outreach.py +++ b/backend/routes/outreach.py @@ -116,11 +116,16 @@ def _send_smtp(to: str, subject: str, body: str, account: str = "partner", html: msg = _build_message(to, subject, body + _LEGAL_FOOTER, account, html=html) msg_bytes = msg.as_bytes() ctx = ssl.create_default_context() - with smtplib.SMTP(_SMTP_HOST, _SMTP_PORT, timeout=15) as s: - s.ehlo() - s.starttls(context=ctx) - s.login(acc["user"], acc["pass"]) - s.sendmail(acc["from"], [to], msg_bytes) + if _SMTP_PORT == 465: + with smtplib.SMTP_SSL(_SMTP_HOST, _SMTP_PORT, context=ctx, timeout=15) as s: + s.login(acc["user"], acc["pass"]) + s.sendmail(acc["from"], [to], msg_bytes) + else: + with smtplib.SMTP(_SMTP_HOST, _SMTP_PORT, timeout=15) as s: + s.ehlo() + s.starttls(context=ctx) + s.login(acc["user"], acc["pass"]) + s.sendmail(acc["from"], [to], msg_bytes) _imap_save_sent(msg_bytes, account)