summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--django/core/management/commands/sendtestemail.py17
-rw-r--r--docs/ref/django-admin.txt11
-rw-r--r--docs/releases/6.1.txt3
-rw-r--r--tests/mail/test_sendtestemail.py35
5 files changed, 61 insertions, 6 deletions
diff --git a/AUTHORS b/AUTHORS
index c85a9a23e3..5b06d4ef2f 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -788,6 +788,7 @@ answer newbie questions, and generally made Django that much better:
Mushtaq Ali <mushtaak@gmail.com>
Mykola Zamkovoi <nickzam@gmail.com>
Nadège Michel <michel.nadege@gmail.com>
+ Naga Kartheek Reddy Kona <konanagakartheek@gmail.com>
Nagy Károly <charlie@rendszergazda.com>
Nasimul Haque <nasim.haque@gmail.com>
Nasir Hussain <nasirhjafri@gmail.com>
diff --git a/django/core/management/commands/sendtestemail.py b/django/core/management/commands/sendtestemail.py
index fbb2a7856e..cfad05f5b8 100644
--- a/django/core/management/commands/sendtestemail.py
+++ b/django/core/management/commands/sendtestemail.py
@@ -28,8 +28,16 @@ class Command(BaseCommand):
action="store_true",
help="Send a test email to the addresses specified in settings.ADMINS.",
)
+ parser.add_argument(
+ "--using",
+ default=None,
+ help=(
+ "Specify the MAILERS alias to use for sending the test email. "
+ "Defaults to 'default'."
+ ),
+ )
- def handle(self, *args, **kwargs):
+ def handle(self, *args, using=None, **kwargs):
subject = "Test email from %s on %s" % (socket.gethostname(), timezone.now())
send_mail(
@@ -37,10 +45,13 @@ class Command(BaseCommand):
message="If you're reading this, it was successful.",
from_email=None,
recipient_list=kwargs["email"],
+ using=using,
)
if kwargs["managers"]:
- mail_managers(subject, "This email was sent to the site managers.")
+ mail_managers(
+ subject, "This email was sent to the site managers.", using=using
+ )
if kwargs["admins"]:
- mail_admins(subject, "This email was sent to the site admins.")
+ mail_admins(subject, "This email was sent to the site admins.", using=using)
diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt
index fc8de971ec..8e3de60c4f 100644
--- a/docs/ref/django-admin.txt
+++ b/docs/ref/django-admin.txt
@@ -1069,8 +1069,15 @@ recipient(s) specified. For example:
django-admin sendtestemail foo@example.com bar@example.com
-There are a couple of options, and you may use any combination of them
-together:
+The following options may be used in any combination with each other and with
+recipient email arguments.
+
+.. django-admin-option:: --using ALIAS
+
+.. versionadded:: 6.1
+
+Specifies the :setting:`MAILERS` alias to use for sending the test email to
+the recipients given as arguments. Defaults to the ``"default"`` mailer.
.. django-admin-option:: --managers
diff --git a/docs/releases/6.1.txt b/docs/releases/6.1.txt
index 123486f242..adb66a013d 100644
--- a/docs/releases/6.1.txt
+++ b/docs/releases/6.1.txt
@@ -274,6 +274,9 @@ Management Commands
:data:`~django.db.models.signals.m2m_changed` signals with ``raw=True`` when
loading fixtures.
+* The :djadmin:`sendtestemail` command now supports a :option:`--using
+ <sendtestemail --using>` option to specify the :setting:`MAILERS` alias.
+
Models
~~~~~~
diff --git a/tests/mail/test_sendtestemail.py b/tests/mail/test_sendtestemail.py
index 1bc500237b..d07b348fc1 100644
--- a/tests/mail/test_sendtestemail.py
+++ b/tests/mail/test_sendtestemail.py
@@ -1,4 +1,5 @@
from django.core import mail
+from django.core.mail import MailerDoesNotExist
from django.core.management import CommandError, call_command
from django.test import SimpleTestCase, override_settings
@@ -6,7 +7,10 @@ from django.test import SimpleTestCase, override_settings
@override_settings(
ADMINS=["admin@example.com", "admin_and_manager@example.com"],
MANAGERS=["manager@example.com", "admin_and_manager@example.com"],
- MAILERS={"default": {"BACKEND": "django.core.mail.backends.locmem.EmailBackend"}},
+ MAILERS={
+ "default": {"BACKEND": "django.core.mail.backends.locmem.EmailBackend"},
+ "notifications": {"BACKEND": "django.core.mail.backends.locmem.EmailBackend"},
+ },
)
class SendTestEmailManagementCommand(SimpleTestCase):
"""
@@ -108,3 +112,32 @@ class SendTestEmailManagementCommand(SimpleTestCase):
"admin_and_manager@example.com",
],
)
+
+ def test_using_option(self):
+ recipient = "joe@example.com"
+ call_command("sendtestemail", "--using", "notifications", recipient)
+ self.assertEqual(len(mail.outbox), 1)
+ mail_message = mail.outbox[0]
+ self.assertEqual(mail_message.sent_using, "notifications")
+
+ def test_using_default(self):
+ recipient = "joe@example.com"
+ call_command("sendtestemail", recipient)
+ self.assertEqual(len(mail.outbox), 1)
+ mail_message = mail.outbox[0]
+ self.assertEqual(mail_message.sent_using, "default")
+
+ def test_using_option_with_managers(self):
+ call_command("sendtestemail", "--using", "notifications", "--managers")
+ self.assertEqual(len(mail.outbox), 1)
+ self.assertEqual(mail.outbox[0].sent_using, "notifications")
+
+ def test_using_option_with_admins(self):
+ call_command("sendtestemail", "--using", "notifications", "--admins")
+ self.assertEqual(len(mail.outbox), 1)
+ self.assertEqual(mail.outbox[0].sent_using, "notifications")
+
+ def test_using_nonexistent_mailer(self):
+ msg = "The mailer 'nonexistent' is not configured."
+ with self.assertRaisesMessage(MailerDoesNotExist, msg):
+ call_command("sendtestemail", "--using", "nonexistent", "joe@example.com")