Skip to content

Commit

Permalink
Clean code of send_test_email command.
Browse files Browse the repository at this point in the history
* Derive from sendtestemail command of Django.
* Remove unwanted imported.
* Allow test email to admin and managers.
  • Loading branch information
umairwaheed authored and timabbott committed Feb 11, 2017
1 parent ef0d2a4 commit 00f8239
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions zerver/management/commands/send_test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,22 @@

from typing import Any

from argparse import ArgumentParser
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from django.core.mail import send_mail, BadHeaderError
from django.core.mail import mail_admins, mail_managers, send_mail
from django.core.management.commands import sendtestemail

class Command(BaseCommand):
help = """Send email to specified email address."""

def add_arguments(self, parser):
# type: (ArgumentParser) -> None
parser.add_argument('to', metavar='<to>', type=str,
help="email of user to send the email")

def handle(self, *args, **options):
class Command(sendtestemail.Command):
def handle(self, *args, **kwargs):
# type: (*Any, **str) -> None
subject = "Zulip Test email"
message = "Success! If you receive this message, you've successfully " + \
"configured sending email from your Zulip server."
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, kwargs['email'])

if kwargs['managers']:
mail_managers(subject, "This email was sent to the site managers.")

send_mail(subject, message, sender, [to])
if kwargs['admins']:
mail_admins(subject, "This email was sent to the site admins.")

0 comments on commit 00f8239

Please sign in to comment.