From 909b0635c899cfabab068e397fa437b0e6384019 Mon Sep 17 00:00:00 2001 From: Ashish Date: Sat, 2 Apr 2016 20:33:29 +0530 Subject: [PATCH] Add management command to test sending email. Fixes: #622. [With cleanups/doc tweaks by tabbott] --- README.prod.md | 5 ++++- zerver/management/commands/send_test_email.py | 21 +++++++++++++++++++ zproject/local_settings_template.py | 3 +++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 zerver/management/commands/send_test_email.py diff --git a/README.prod.md b/README.prod.md index 9255d7b874..f7dc5d98bf 100644 --- a/README.prod.md +++ b/README.prod.md @@ -148,8 +148,11 @@ need to do some additional setup documented in the `settings.py` template: * For Google authentication, you need to follow the configuration instructions around `GOOGLE_OAUTH2_CLIENT_ID` and `GOOGLE_CLIENT_ID`. + * For Email authentication, you will need to follow the configuration - instructions around outgoing SMTP from Django. + instructions for outgoing SMTP from Django. You can use `manage.py + send_test_email username@example.com` to test whether you've + successfully configured outgoing SMTP. You should be able to login now. If you get an error, check `/var/log/zulip/errors.log` for a traceback, and consult the next diff --git a/zerver/management/commands/send_test_email.py b/zerver/management/commands/send_test_email.py new file mode 100644 index 0000000000..bcb70f9c40 --- /dev/null +++ b/zerver/management/commands/send_test_email.py @@ -0,0 +1,21 @@ +from __future__ import absolute_import + +from django.core.management.base import BaseCommand, CommandError +from django.conf import settings +from django.core.mail import send_mail, BadHeaderError + +class Command(BaseCommand): + help = """Send email to specified email address.""" + + def add_arguments(self, parser): + parser.add_argument('to', metavar='', type=str, + help="email of user to send the email") + + def handle(self, *args, **options): + subject = "Zulip Test email" + message = "Success! If you receive this message, you've successfully " + \ + "configured sending email from your Zulip server." + sender = settings.DEFAULT_FROM_EMAIL + to = options['to'] + + send_mail(subject, message, sender, [to]) diff --git a/zproject/local_settings_template.py b/zproject/local_settings_template.py index 6dac781b79..bc6cce0b33 100644 --- a/zproject/local_settings_template.py +++ b/zproject/local_settings_template.py @@ -61,6 +61,9 @@ SSO_APPEND_DOMAIN = None # that account as "less secure": # https://support.google.com/mail/answer/14257. # +# You can quickly test your sending email configuration using: +# ./manage.py send_test_email username@example.com +# # A common problem is hosting providers that block outgoing SMTP traffic. # # With the exception of reading EMAIL_HOST_PASSWORD from