send_email: Only warn if EMAIL_HOST_PASSWORD is unset, not "".

Some email hosts actually do want an empty password; since the default
is `None`, we should key on that, and not just being false-y.
This commit is contained in:
Alex Vandiver 2022-04-12 14:43:41 -07:00 committed by Tim Abbott
parent 9f8022de5e
commit ee04f42897
2 changed files with 11 additions and 1 deletions

View File

@ -597,7 +597,7 @@ def log_email_config_errors() -> None:
The purpose of this function is to log (potential) config errors,
but without raising an exception.
"""
if settings.EMAIL_HOST_USER and not settings.EMAIL_HOST_PASSWORD:
if settings.EMAIL_HOST_USER and settings.EMAIL_HOST_PASSWORD is None:
logger.error(
"An SMTP username was set (EMAIL_HOST_USER), but password is unset (EMAIL_HOST_PASSWORD)."
)

View File

@ -168,3 +168,13 @@ class TestSendEmail(ZulipTestCase):
"An SMTP username was set (EMAIL_HOST_USER), but password is unset (EMAIL_HOST_PASSWORD)."
],
)
# Empty string is OK
with self.settings(EMAIL_HOST_USER="test", EMAIL_HOST_PASSWORD=""):
send_email(
"zerver/emails/password_reset",
to_emails=[hamlet],
from_name="From Name",
from_address=FromAddress.NOREPLY,
language="en",
)