Ticket #5746: return_path.diff
File return_path.diff, 6.7 KB (added by , 17 years ago) |
---|
-
django/core/mail.py
182 182 if not email_message.to: 183 183 return False 184 184 try: 185 self.connection.sendmail(email_message. from_email,185 self.connection.sendmail(email_message.return_path, 186 186 email_message.recipients(), 187 187 email_message.message().as_string()) 188 188 except: … … 200 200 encoding = None # None => use settings default 201 201 202 202 def __init__(self, subject='', body='', from_email=None, to=None, bcc=None, 203 connection=None, attachments=None, headers=None ):203 connection=None, attachments=None, headers=None, return_path=None): 204 204 """ 205 205 Initialise a single email message (which can be sent to multiple 206 206 recipients). … … 212 212 self.to = to or [] 213 213 self.bcc = bcc or [] 214 214 self.from_email = from_email or settings.DEFAULT_FROM_EMAIL 215 self.return_path = return_path or self.from_email 215 216 self.subject = subject 216 217 self.body = body 217 218 self.attachments = attachments or [] -
tests/modeltests/test_client/views.py
151 151 ['first@example.com', 'second@example.com']).send() 152 152 return HttpResponse("Mail sent") 153 153 154 def mail_sending_view_with_return_path(request): 155 EmailMessage( 156 "Test message", 157 "This is a test email", 158 "from@example.com", 159 ['first@example.com', 'second@example.com'], 160 return_path='return_path@example.com').send() 161 return HttpResponse("Mail sent") 162 154 163 def mass_mail_sending_view(request): 155 164 m1 = EmailMessage( 156 165 'First Test message', … … 161 170 'Second Test message', 162 171 'This is the second test email', 163 172 'from@example.com', 164 ['second@example.com', 'third@example.com']) 173 ['second@example.com', 'third@example.com'], 174 return_path='return_path@example.com') 165 175 166 176 c = SMTPConnection() 167 177 c.send_messages([m1,m2]) -
tests/modeltests/test_client/models.py
331 331 self.assertEqual(mail.outbox[0].subject, 'Test message') 332 332 self.assertEqual(mail.outbox[0].body, 'This is a test email') 333 333 self.assertEqual(mail.outbox[0].from_email, 'from@example.com') 334 self.assertEqual(mail.outbox[0].return_path, 'from@example.com') 334 335 self.assertEqual(mail.outbox[0].to[0], 'first@example.com') 335 336 self.assertEqual(mail.outbox[0].to[1], 'second@example.com') 336 337 338 def test_mail_sending_with_return_path(self): 339 "Test that mail is redirected to a dummy outbox during test setup (with return_path set correctly)" 340 341 response = self.client.get('/test_client/mail_sending_view_with_return_path/') 342 self.assertEqual(response.status_code, 200) 343 344 self.assertEqual(len(mail.outbox), 1) 345 self.assertEqual(mail.outbox[0].subject, 'Test message') 346 self.assertEqual(mail.outbox[0].body, 'This is a test email') 347 self.assertEqual(mail.outbox[0].from_email, 'from@example.com') 348 self.assertEqual(mail.outbox[0].return_path, 'return_path@example.com') 349 self.assertEqual(mail.outbox[0].to[0], 'first@example.com') 350 self.assertEqual(mail.outbox[0].to[1], 'second@example.com') 351 337 352 def test_mass_mail_sending(self): 338 353 "Test that mass mail is redirected to a dummy outbox during test setup" 339 354 … … 344 359 self.assertEqual(mail.outbox[0].subject, 'First Test message') 345 360 self.assertEqual(mail.outbox[0].body, 'This is the first test email') 346 361 self.assertEqual(mail.outbox[0].from_email, 'from@example.com') 362 self.assertEqual(mail.outbox[0].return_path, 'from@example.com') 347 363 self.assertEqual(mail.outbox[0].to[0], 'first@example.com') 348 364 self.assertEqual(mail.outbox[0].to[1], 'second@example.com') 349 365 350 366 self.assertEqual(mail.outbox[1].subject, 'Second Test message') 351 367 self.assertEqual(mail.outbox[1].body, 'This is the second test email') 352 368 self.assertEqual(mail.outbox[1].from_email, 'from@example.com') 369 self.assertEqual(mail.outbox[1].return_path, 'return_path@example.com') 353 370 self.assertEqual(mail.outbox[1].to[0], 'second@example.com') 354 371 self.assertEqual(mail.outbox[1].to[1], 'third@example.com') 355 372 -
tests/modeltests/test_client/urls.py
17 17 (r'^session_view/$', views.session_view), 18 18 (r'^broken_view/$', views.broken_view), 19 19 (r'^mail_sending_view/$', views.mail_sending_view), 20 (r'^mail_sending_view_with_return_path/$', views.mail_sending_view_with_return_path), 20 21 (r'^mass_mail_sending_view/$', views.mass_mail_sending_view) 21 22 ) -
docs/email.txt
65 65 * ``auth_password``: The optional password to use to authenticate to the 66 66 SMTP server. If this isn't provided, Django will use the value of the 67 67 ``EMAIL_HOST_PASSWORD`` setting. 68 * ``return_path``: An optional string used to specifiy the SMTP envelope 69 sender. If this isn't provided, Django will use ``from_email`` instead. 68 70 69 71 .. _smtplib docs: http://www.python.org/doc/current/lib/module-smtplib.html 70 72 … … 81 83 82 84 (subject, message, from_email, recipient_list) 83 85 84 ``fail_silently``, ``auth_user`` and ``auth_password`` have the same functions85 as in ``send_mail()``.86 ``fail_silently``, ``auth_user``, ``auth_password`` and ``return_path`` have the 87 same functions as in ``send_mail()``. 86 88 87 89 Each separate element of ``datatuple`` results in a separate e-mail message. 88 90 As in ``send_mail()``, recipients in the same ``recipient_list`` will all see … … 245 247 caller to ensure header names and values are in the correct format for 246 248 an e-mail message. 247 249 250 * ``return_path``: A string used to specifiy the SMTP envelope 251 sender. If this isn't provided, Django will use ``from_email`` instead. 252 248 253 For example:: 249 254 250 255 email = EmailMessage('Hello', 'Body goes here', 'from@example.com',