简体   繁体   中英

Getting outlook email with same format as outlook [using python]

I am able to get all emails from outlook and save them into a .txt file, but the format is destroyed [can't fetch HTML tags, tables etc] I also save all messages into a .msg file but still, the format is missing. Is there any way to save them into some file format that can hold the same format as it was into outlook? The code, I was using is:

import win32com.client
import os
import time
import datetime as dt
from datetime import datetime, timedelta
import re

....
....
....

delimiter = "------------------------------------------------------------------"
with open('readme_1.msg', 'w+') as f:
    for message in messages_1:
        f.write(message.Subject)
        f.write(message.ReceivedTime.strftime('%d-%b-%Y %H:%M %p')+"\n")
        f.write(message.body)
        f.write(delimiter+"\n")

In the code you are using the plain-text property:

f.write(message.body)

Instead, it seems you are interested in the [HTMLBody][1] property which returns or sets a string representing the HTML body of the specified item.

Note, setting the HTMLBody property will always update the Body property immediately.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM