Ticket #17444: set_mail_to_header.2.diff
File set_mail_to_header.2.diff, 2.4 KB (added by , 13 years ago) |
---|
-
tests/regressiontests/mail/tests.py
96 96 message = email.message() 97 97 self.assertEqual(message['From'], 'from@example.com') 98 98 99 def test_to_header(self): 100 """ 101 Make sure we can manually set the To header (#17444) 102 """ 103 email = EmailMessage('Subject', 'Content', 'bounce@example.com', 104 ['list-subscriber@example.com', 'list-subscriber2@example.com'], 105 headers={'To': 'mailing-list@example.com'}) 106 message = email.message() 107 self.assertEqual(message['To'], 'mailing-list@example.com') 108 self.assertEqual(email.to, ['list-subscriber@example.com', 'list-subscriber2@example.com']) 109 110 # If we don't set the To header manually, it should default to the `to` argument to the constructor 111 email = EmailMessage('Subject', 'Content', 'bounce@example.com', 112 ['list-subscriber@example.com', 'list-subscriber2@example.com']) 113 message = email.message() 114 self.assertEqual(message['To'], 'list-subscriber@example.com, list-subscriber2@example.com') 115 self.assertEqual(email.to, ['list-subscriber@example.com', 'list-subscriber2@example.com']) 116 99 117 def test_multiple_message_call(self): 100 118 """ 101 119 Regression for #13259 - Make sure that headers are not changed when -
django/core/mail/message.py
215 215 msg = self._create_message(msg) 216 216 msg['Subject'] = self.subject 217 217 msg['From'] = self.extra_headers.get('From', self.from_email) 218 msg['To'] = ', '.join(self.to)218 msg['To'] = self.extra_headers.get('To', ', '.join(self.to)) 219 219 if self.cc: 220 220 msg['Cc'] = ', '.join(self.cc) 221 221 … … 227 227 if 'message-id' not in header_names: 228 228 msg['Message-ID'] = make_msgid() 229 229 for name, value in self.extra_headers.items(): 230 if name.lower() == 'from': # From isalready handled230 if name.lower() in ('from', 'to'): # From and To are already handled 231 231 continue 232 232 msg[name] = value 233 233 return msg