Send an email containing DataFrames as tables in the email body

Viewed 7441

I've created several DataFrames and would like to add them to the body of the email I am sending. Do I need to convert each DataFrame to html and then the html to a table? It's the last step that I am having an issue with. My code is below and at the moment it sends the html format of the dataframe (not a nice table).

import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = 'my email address'
mail.Subject = 'My subject'

html1 = mydataframe.to_html()
mail.Body = hmtl1
mail.Send()
1 Answers

Change

mail.Body = hmtl1 

to

mail.HTMLBody = hmtl1

(credit to a colleague)

Related