#36244: Email sending with HTML alternative may not generate content
-------------------------------------+-------------------------------------
     Reporter:  WeeDom               |                    Owner:  (none)
         Type:  Bug                  |                   Status:  closed
    Component:  Core (Mail)          |                  Version:  5.1
     Severity:  Normal               |               Resolution:  invalid
     Keywords:  safestring           |             Triage Stage:
  send_email html_message            |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

 * component:  Uncategorized => Core (Mail)
 * easy:  1 => 0
 * has_patch:  1 => 0
 * keywords:  safestring. => safestring send_email html_message
 * resolution:   => invalid
 * status:  new => closed
 * summary:  safestring => Email sending with HTML alternative may not
     generate content

Comment:

 Hello WeeDom,

 With the code that you provided, I created an isolated test case (removing
 moving pieces), which asserts about the HTML body of the sent email. The
 test passes and it shows the correct and expected HTML content. The test
 case:
 {{{#!python
 class OrderTestCase(TestCase):

     def test_ticket_36244(self):
         context = {
             "name": "some name",
             "phone": "some phone",
             "email": "some email",
             "address1": "some address1",
             "comments": "some comments",
         }
         vendor_email_html = (
             render_to_string("order/order_email_to_vendor.html", context)
             + " testing by Dom"
         )
         vendor_email_plain = strip_tags(vendor_email_html)

         mail.send_mail(
             "New Order",
             vendor_email_plain,
             "[email protected]",
             ["[email protected]"],
             fail_silently=False,
             html_message=vendor_email_html,
         )

         self.assertEqual(len(mail.outbox), 1)
         msg = mail.outbox[0]
         expected = """<!DOCTYPE html>
 <html>
 <head>
 <title>New Order</title>
 </head>
 <body>
     <p>Hi, AK,</p>
     <p>An order has been placed by some name. Details below:</p>
     <ul>
         <li>Name: some name</li>
         <li>Phone: some phone</li>
         <li>Email: some email</li>
         <li>Address: some address1</li>
         <li>Comments: some comments</li>
     </ul>
     <p>Cheers,<br>Your friendly robot helper.</p>
 </body>
 </html>
  testing by Dom"""
         self.assertEqual(msg.alternatives[0][0], expected)
 }}}

 Because of the above, and lack of reproduction steps, this report seems
 better suited to be a support request. The best place to get answers to
 your issue is using any of the user support channels from
 [https://docs.djangoproject.com/en/dev/faq/help/#how-do-i-do-x-why-
 doesn-t-y-work-where-can-i-go-to-get-help this link].

 Since the goal of this issue tracker is to track issues about Django
 itself, and your issue seems, at first, to be located in your custom code,
 I'll be closing this ticket as invalid following the
 [https://docs.djangoproject.com/en/dev/internals/contributing/triaging-
 tickets/#closing-tickets ticket triaging process]. If, after debugging,
 you find out that this is indeed a bug in Django, please re-open with the
 specific details and please be sure to include a small Django project to
 reproduce or a failing test case.

 I'm also unchecking the "has patch" flag since I can't find a PR for this
 ticket.

 Thank you!
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36244#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019582672294-9c053836-813d-4516-b710-495acd6f43c5-000000%40eu-central-1.amazonses.com.

Reply via email to