From 1d167974fff75d01313887a9c6dae9eb31bd9994 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Wed, 29 Apr 2026 12:31:23 -0700 Subject: [PATCH] fix(proxy): case-insensitive SMTP_USE_SSL check + lowercase test --- litellm/proxy/utils.py | 2 +- tests/test_litellm/proxy/test_utils.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index 7b2d7aec88b..2dda9f7e632 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -4717,7 +4717,7 @@ async def send_email( # Attach the body to the email email_message.attach(MIMEText(html, "html")) - smtp_use_ssl = os.getenv("SMTP_USE_SSL", "False") == "True" + smtp_use_ssl = os.getenv("SMTP_USE_SSL", "False").lower() == "true" use_ssl = smtp_use_ssl or smtp_port == 465 try: diff --git a/tests/test_litellm/proxy/test_utils.py b/tests/test_litellm/proxy/test_utils.py index 528c9a9ba12..524b10416ca 100644 --- a/tests/test_litellm/proxy/test_utils.py +++ b/tests/test_litellm/proxy/test_utils.py @@ -80,6 +80,31 @@ async def test_send_email_smtp_use_ssl_env_forces_ssl(monkeypatch): mock_server.starttls.assert_not_called() +@pytest.mark.asyncio +async def test_send_email_smtp_use_ssl_env_lowercase(monkeypatch): + """SMTP_USE_SSL=true (lowercase) must also trigger SMTP_SSL.""" + monkeypatch.setenv("SMTP_HOST", "smtp.example.com") + monkeypatch.setenv("SMTP_PORT", "2525") + monkeypatch.setenv("SMTP_USE_SSL", "true") + monkeypatch.setenv("SMTP_SENDER_EMAIL", "noreply@example.com") + + mock_server = MagicMock() + mock_server.__enter__ = lambda s: s + mock_server.__exit__ = MagicMock(return_value=False) + + with ( + patch("smtplib.SMTP_SSL", return_value=mock_server) as mock_ssl, + patch("smtplib.SMTP") as mock_plain, + ): + await send_email( + receiver_email="user@example.com", + subject="Test", + html="

Hi

", + ) + mock_ssl.assert_called_once_with(host="smtp.example.com", port=2525) + mock_plain.assert_not_called() + + @pytest.mark.asyncio async def test_send_email_port_587_uses_starttls(monkeypatch): """Port 587 (default) must use SMTP + starttls — backwards compat regression guard."""