Reputation: 335
I'm writing a script to email a pandas dataframe as a table to several people. I have my dataframe frame
:
SITE ... VISITS
438 1 ... 104
439 2 ... 104
440 3 ... 104
504 4 ... 215
I'm trying to create a pretty_html_table that I can email using:
from pretty_html_table import build_table
html_table = build_table(frame, 'blue_light')
However, instead of emailing a table, the script emails a bunch of html text!
<p><table border="0" class="dataframe">
<thead>
<tr style="text-align: right;">
<th style = "background-color: #FFFFFF;font-family: Century Gothic;font-size: medium;color: #305496;text-align: left;border-bottom: 2px solid #305496;padding: 0px 20px 0px 0px">SITE</th>
etcetera, etcetera ...
I'm trying to append this table to an email like so:
import win32com.client as win32
def report_email(email):
html_table = build_table(frame, 'blue_light')
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = email
mail.Subject = 'Table below'
mail.Body = "Hi, here is a table" + html_table
return mail.Send()
Thanks so much for all you help!
Upvotes: 0
Views: 4291
Reputation: 14233
pretty_html_table.build_table
is expected to return the HTML code for the table. The problem is that you use mail.Body
. Use mail.HTMLBody
instead.
Here is MailItem.HTMLBody docs
Upvotes: 2