diff --git a/zerver/management/commands/send_test_email.py b/zerver/management/commands/send_test_email.py index e655518798..b29089b21f 100644 --- a/zerver/management/commands/send_test_email.py +++ b/zerver/management/commands/send_test_email.py @@ -1,13 +1,18 @@ from typing import Any +from django.conf import settings from django.core.mail import mail_admins, mail_managers, send_mail +from django.core.management import CommandError from django.core.management.commands import sendtestemail from zerver.lib.send_email import FromAddress class Command(sendtestemail.Command): def handle(self, *args: Any, **kwargs: str) -> None: + if settings.WARN_NO_EMAIL: + raise CommandError("Outgoing email not yet configured, see\n " + "https://zulip.readthedocs.io/en/latest/production/email.html") subject = "Zulip Test email" message = ("Success! If you receive this message, you've " "successfully configured sending email from your " diff --git a/zerver/tests/test_management_commands.py b/zerver/tests/test_management_commands.py index 3e3101aca4..ca74ea2f74 100644 --- a/zerver/tests/test_management_commands.py +++ b/zerver/tests/test_management_commands.py @@ -28,6 +28,11 @@ class TestCheckConfig(ZulipTestCase): with self.assertRaisesRegex(CommandError, "Error: You must set asdf in /etc/zulip/settings.py."): check_config() + @override_settings(WARN_NO_EMAIL=True) + def test_check_send_email(self) -> None: + with self.assertRaisesRegex(CommandError, "Outgoing email not yet configured, see"): + call_command("send_test_email", 'test@example.com') + class TestZulipBaseCommand(ZulipTestCase): def setUp(self) -> None: self.zulip_realm = get_realm("zulip")