mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-29 17:36:49 +01:00
Fix for emails missing the HTML messages.
This commit is contained in:
parent
be03eeee2e
commit
4f5b117250
@ -26,6 +26,7 @@ Changelog
|
||||
* Fix: Page Copy will now also copy ParentalManyToMany field relations (LB (Ben Johnston))
|
||||
* Fix: Admin HTML header now includes correct language code (Matt Westcott)
|
||||
* Fix: Unclear error message when saving image after focal point edit (Hugo van den Berg)
|
||||
* Fix: `send_mail` now correctly uses the `html_message` kwarg for HTML messages (Tiago Requeijo)
|
||||
|
||||
|
||||
2.4 (19.12.2018)
|
||||
|
@ -42,6 +42,7 @@ Bug fixes
|
||||
* Admin HTML header now includes correct language code (Matt Westcott)
|
||||
* Unclear error message when saving image after focal point edit (Hugo van den Berg)
|
||||
* Fix: Increase max length on ``Embed.thumbnail_url`` to 255 characters (Kevin Howbrook)
|
||||
* Fix: ``send_mail`` now correctly uses the ``html_message`` kwarg for HTML messages (Tiago Requeijo)
|
||||
|
||||
|
||||
Upgrade considerations
|
||||
|
@ -141,6 +141,29 @@ class TestSendMail(TestCase):
|
||||
self.assertEqual(mail.outbox[0].to, ["nobody@email.com"])
|
||||
self.assertEqual(mail.outbox[0].from_email, "webmaster@localhost")
|
||||
|
||||
def test_send_html_email(self):
|
||||
"""Test that the kwarg 'html_message' works as expected on send_mail by creating 'alternatives' on the EmailMessage object"""
|
||||
|
||||
send_mail("Test HTML subject", "TEXT content", ["has.html@email.com"], html_message="<h2>Test HTML content</h2>")
|
||||
send_mail("Test TEXT subject", "TEXT content", ["mr.plain.text@email.com"])
|
||||
|
||||
# Check that the emails were sent
|
||||
self.assertEqual(len(mail.outbox), 2)
|
||||
|
||||
# check that the first email is the HTML email
|
||||
email_message = mail.outbox[0]
|
||||
self.assertEqual(email_message.subject, "Test HTML subject")
|
||||
self.assertEqual(email_message.alternatives, [('<h2>Test HTML content</h2>', 'text/html')])
|
||||
self.assertEqual(email_message.body, "TEXT content") # note: plain text will alwasy be added to body, even with alternatives
|
||||
self.assertEqual(email_message.to, ["has.html@email.com"])
|
||||
|
||||
# confirm that without html_message kwarg we do not get 'alternatives'
|
||||
email_message = mail.outbox[1]
|
||||
self.assertEqual(email_message.subject, "Test TEXT subject")
|
||||
self.assertEqual(email_message.alternatives, [])
|
||||
self.assertEqual(email_message.body, "TEXT content")
|
||||
self.assertEqual(email_message.to, ["mr.plain.text@email.com"])
|
||||
|
||||
|
||||
class TestTagsAutocomplete(TestCase, WagtailTestUtils):
|
||||
def setUp(self):
|
||||
|
@ -222,13 +222,13 @@ def send_mail(subject, message, recipient_list, from_email=None, **kwargs):
|
||||
password=kwargs.get('auth_password', None),
|
||||
fail_silently=kwargs.get('fail_silently', None),
|
||||
)
|
||||
kwargs = {
|
||||
multi_alt_kwargs = {
|
||||
'connection': connection,
|
||||
'headers': {
|
||||
'Auto-Submitted': 'auto-generated',
|
||||
}
|
||||
}
|
||||
mail = EmailMultiAlternatives(subject, message, from_email, recipient_list, **kwargs)
|
||||
mail = EmailMultiAlternatives(subject, message, from_email, recipient_list, **multi_alt_kwargs)
|
||||
html_message = kwargs.get('html_message', None)
|
||||
if html_message:
|
||||
mail.attach_alternative(html_message, 'text/html')
|
||||
|
Loading…
Reference in New Issue
Block a user