问题描述
我正在尝试使用呈现 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,51)">Created</th>
<th style=3D"border-bottom:2px solid rgb(17,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,201=
)">2021-02-23 17:08:48</td>
<td class=3D"x_table_text" style=3D"border:1px solid rgb(191,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,201=
)">Happy Tuesday</td>
<td class=3D"x_table_numerical" style=3D"border:1px solid rgb(191,201=
)">2021-02-23 18:32:35</td>
<td class=3D"x_table_text" style=3D"border:1px solid rgb(191,201)">sm=
porter2</td>
</tr>
</tbody>
</table>
"""
当我发送它时,它会加载为常规文本。我试图让它呈现为普通的 html,以便它像网页一样显示在电子邮件中。我怎样才能将此渲染为 html
解决方法
试着像这样包裹你的身体(你的 htmlcode):
body = HTMLBody(
'<html><body>Hello logo: <img src="cid:%s"></body></html>' % logo_filename
)