Fixed #17444 -- Made it possible to customize the 'To' header in emails.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17293 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
e5999ce234
commit
5e75678c8b
|
@ -215,7 +215,7 @@ class EmailMessage(object):
|
||||||
msg = self._create_message(msg)
|
msg = self._create_message(msg)
|
||||||
msg['Subject'] = self.subject
|
msg['Subject'] = self.subject
|
||||||
msg['From'] = self.extra_headers.get('From', self.from_email)
|
msg['From'] = self.extra_headers.get('From', self.from_email)
|
||||||
msg['To'] = ', '.join(self.to)
|
msg['To'] = self.extra_headers.get('To', ', '.join(self.to))
|
||||||
if self.cc:
|
if self.cc:
|
||||||
msg['Cc'] = ', '.join(self.cc)
|
msg['Cc'] = ', '.join(self.cc)
|
||||||
|
|
||||||
|
@ -227,7 +227,7 @@ class EmailMessage(object):
|
||||||
if 'message-id' not in header_names:
|
if 'message-id' not in header_names:
|
||||||
msg['Message-ID'] = make_msgid()
|
msg['Message-ID'] = make_msgid()
|
||||||
for name, value in self.extra_headers.items():
|
for name, value in self.extra_headers.items():
|
||||||
if name.lower() == 'from': # From is already handled
|
if name.lower() in ('from', 'to'): # From and To are already handled
|
||||||
continue
|
continue
|
||||||
msg[name] = value
|
msg[name] = value
|
||||||
return msg
|
return msg
|
||||||
|
|
|
@ -96,6 +96,24 @@ class MailTests(TestCase):
|
||||||
message = email.message()
|
message = email.message()
|
||||||
self.assertEqual(message['From'], 'from@example.com')
|
self.assertEqual(message['From'], 'from@example.com')
|
||||||
|
|
||||||
|
def test_to_header(self):
|
||||||
|
"""
|
||||||
|
Make sure we can manually set the To header (#17444)
|
||||||
|
"""
|
||||||
|
email = EmailMessage('Subject', 'Content', 'bounce@example.com',
|
||||||
|
['list-subscriber@example.com', 'list-subscriber2@example.com'],
|
||||||
|
headers={'To': 'mailing-list@example.com'})
|
||||||
|
message = email.message()
|
||||||
|
self.assertEqual(message['To'], 'mailing-list@example.com')
|
||||||
|
self.assertEqual(email.to, ['list-subscriber@example.com', 'list-subscriber2@example.com'])
|
||||||
|
|
||||||
|
# If we don't set the To header manually, it should default to the `to` argument to the constructor
|
||||||
|
email = EmailMessage('Subject', 'Content', 'bounce@example.com',
|
||||||
|
['list-subscriber@example.com', 'list-subscriber2@example.com'])
|
||||||
|
message = email.message()
|
||||||
|
self.assertEqual(message['To'], 'list-subscriber@example.com, list-subscriber2@example.com')
|
||||||
|
self.assertEqual(email.to, ['list-subscriber@example.com', 'list-subscriber2@example.com'])
|
||||||
|
|
||||||
def test_multiple_message_call(self):
|
def test_multiple_message_call(self):
|
||||||
"""
|
"""
|
||||||
Regression for #13259 - Make sure that headers are not changed when
|
Regression for #13259 - Make sure that headers are not changed when
|
||||||
|
|
Loading…
Reference in New Issue