diff --git a/django/core/mail/__init__.py b/django/core/mail/__init__.py index d7a868dfc2b..8d064223cd9 100644 --- a/django/core/mail/__init__.py +++ b/django/core/mail/__init__.py @@ -87,7 +87,7 @@ def mail_admins(subject, message, fail_silently=False, connection=None): """Sends a message to the admins, as defined by the ADMINS setting.""" if not settings.ADMINS: return - EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message, + EmailMessage(u'%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject), message, settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS], connection=connection).send(fail_silently=fail_silently) @@ -96,7 +96,7 @@ def mail_managers(subject, message, fail_silently=False, connection=None): """Sends a message to the managers, as defined by the MANAGERS setting.""" if not settings.MANAGERS: return - EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message, + EmailMessage(u'%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject), message, settings.SERVER_EMAIL, [a[1] for a in settings.MANAGERS], connection=connection).send(fail_silently=fail_silently) diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py index b0c60d836e4..d2f7562d8f4 100644 --- a/tests/regressiontests/mail/tests.py +++ b/tests/regressiontests/mail/tests.py @@ -343,3 +343,23 @@ class MailTests(TestCase): settings.ADMINS = old_admins settings.MANAGERS = old_managers + def test_mail_prefix(self): + """Test prefix argument in manager/admin mail.""" + # Regression for #13494. + old_admins = settings.ADMINS + old_managers = settings.MANAGERS + settings.ADMINS = settings.MANAGERS = [('nobody','nobody@example.com')] + + mail_managers(ugettext_lazy('Subject'), 'Content') + self.assertEqual(len(mail.outbox), 1) + message = mail.outbox[0] + self.assertEqual(message.subject, '[Django] Subject') + + mail.outbox = [] + mail_admins(ugettext_lazy('Subject'), 'Content') + self.assertEqual(len(mail.outbox), 1) + message = mail.outbox[0] + self.assertEqual(message.subject, '[Django] Subject') + + settings.ADMINS = old_admins + settings.MANAGERS = old_managers