1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #26802 -- Prevented crash when attaching bytes as text message

Thanks Tim Graham for the review.
This commit is contained in:
Claude Paroz
2016-07-01 22:01:58 +02:00
parent 9356f63a99
commit 04b7b28812
2 changed files with 14 additions and 2 deletions

View File

@@ -390,6 +390,14 @@ class MailTests(HeadersCheckMixin, SimpleTestCase):
msgs_sent_num = email.send()
self.assertEqual(msgs_sent_num, 1)
def test_attach_text_as_bytes(self):
msg = EmailMessage('subject', 'body', 'from@example.com', ['to@example.com'])
file_path = os.path.join(os.path.dirname(upath(__file__)), 'attachments', 'file.txt')
with open(file_path, mode='rb') as fh:
msg.attach('file.txt', fh.read())
sent_num = msg.send()
self.assertEqual(sent_num, 1)
def test_dummy_backend(self):
"""
Make sure that dummy backends returns correct number of sent messages