Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send an email containing DataFrames as tables in the email body

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()
like image 689
KSQ Avatar asked Oct 18 '22 05:10

KSQ


1 Answers

Change

mail.Body = hmtl1 

to

mail.HTMLBody = hmtl1

(credit to a colleague)

like image 182
KSQ Avatar answered Oct 20 '22 09:10

KSQ