在电子邮件中呈现 HTML

Rendered HTML in email

我正在尝试使用呈现 html.

的 exchangelib 发送电子邮件

下面是我的电子邮件功能和正文

def send_email(account, subject, body, recipients):
    """
    >>> send_email(account, 'Subject line', 'Hello!', ['info@example.com'])
    """
    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>
"""

当我发送它时,它加载为普通文本。我试图让它正常呈现 html 以便它像网页一样显示在电子邮件中。我怎样才能将此渲染为 html

尝试像这样包装您 body(您的 html 代码):

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