I am using win32com.client , python 2.7.x and outlook 2013 on windows platform.
I need to send the contents of an HTML file to the body of an outlook message.
I here, here and here on how to save excel as HTML and insert data into outlook .
However, when I read the file through win32com.client.Dispatch , instead of viewing the message, I see HTML code.
Here is the code that converts the processed xlsx file to HTML using win32.com .
#Section to convert excel workbook to html myfile = os.getcwd()+ "\\" + outfile newfile = os.getcwd()+ "\\" + "emailData.html" xl = EnsureDispatch('Excel.Application')
The above result is newfile , which is basically an export of an xlsx file saved as html. It then opens through the mail.body handler, which should read and display the actual content in Outlook.
Here is the code for this.
from win32com.client.gencache import EnsureDispatch from win32com.client import constants, Dispatch
So, when I open newfile (html file) using mail.body = open(newfile).read() , it inserts html content into a new Outlook email item.
When I open newfile (html file) with mail.HtmlBody = open(newfile).read() , it gives the following error inside the outlook of the email body
ERROR: This page uses frames, but your browser doesn't support them.
Any ideas on this behavior?
Basically I want to copy / paste an HTML file (which is an xlsx export) in Outlook. Not sure if the above is the correct approach or other alternatives exist.
Is there a way to insert / render HTML frames into the body of an Outlook email?
Any pointers are appreciated.