Read outlook mail in html format
<p>I receive a mail in Microsoft Outlook that contains a html table. I would like to parse this in to a pandas dataframe. </p>

<p>I have already written a script that uses beautiful soup to parse the html text in to the dataframe. But I am struggling with reading the email in html in the first place. </p>

<p>Having found the message I am using the below code to read it in to a text file. But it is writing the text as a /n separated string rather than something like data as I was expecting. Which means that I then can't use beautiful soup to get this in to a dataframe.</p>

<p>I have found lots of examples of how to write and send a html mail but not how to read one in html format. Any ideas?</p>

<pre><code>contents = msg.Body.encode('ascii', 'ignore').decode('ascii')
contents_file = open("U:\body.txt", "w")
contents_file.write(contents)               
contents_file.close()
</code></pre>

<p>Found the answer myself. I should use msg.HTMLBody rather than msg.Body</p>

python html email outlook