Brandon Kauffman
Brandon Kauffman

Reputation: 1865

Rendered HTML in email

I am attempting to send an email using exchangelib that renders html.

below is my email function and body

def send_email(account, subject, body, recipients):
    """
    >>> send_email(account, 'Subject line', 'Hello!', ['[email protected]'])
    """
    to_recipients = []
    for recipient in recipients:
        to_recipients.append(Mailbox(email_address=recipient))
    # Create message
    m = Message(account=account,
                folder=account.sent,
                subject=subject,
                body=body,
                to_recipients=to_recipients)


    m.send_and_save()


 """
<hr>
<table class=3D"x_data_table" style=3D"margin:0px auto;border-collapse:coll=
apse;width:800px;display:inline">
<thead>
<tr>
<th style=3D"border-bottom:2px solid rgb(17, 29, 51)">Item</th>
<th style=3D"border-bottom:2px solid rgb(17, 29, 51)">Created</th>
<th style=3D"border-bottom:2px solid rgb(17, 29, 51)">Created By</th>
</tr>
</thead>
<tbody>
<tr class=3D"x_odd" style=3D"background-color:rgb(245, 245, 245)">
<td class=3D"x_table_long_text" style=3D"border:1px solid rgb(191, 194, 201=
)">I hate myself and want to die</td>
<td class=3D"x_table_numerical" style=3D"border:1px solid rgb(191, 194, 201=
)">2021-02-23 17:08:48</td>
<td class=3D"x_table_text" style=3D"border:1px solid rgb(191, 194, 201)">cb=
eard22</td>
</tr>
<tr class=3D"x_even" style=3D"background-color:rgb(212, 220, 224)">
<td class=3D"x_table_long_text" style=3D"border:1px solid rgb(191, 194, 201=
)">Happy Tuesday</td>
<td class=3D"x_table_numerical" style=3D"border:1px solid rgb(191, 194, 201=
)">2021-02-23 18:32:35</td>
<td class=3D"x_table_text" style=3D"border:1px solid rgb(191, 194, 201)">sm=
porter2</td>
</tr>
</tbody>
</table>
"""

When I send this it loads as regular text. I am attempting to have it render as normal html so that it displays in the email like a web page. How can I have this render as html

Upvotes: 4

Views: 190

Answers (1)

Arjen
Arjen

Reputation: 1161

Try to wrap you body (Your htmlcode) like this:

body = HTMLBody(
  '<html><body>Hello logo: <img src="cid:%s"></body></html>' % logo_filename
)

Upvotes: 5

Related Questions