I am trying to download an email from outlook sent-items. Currently I am able to save is '.msg' format. Is there anyway through which I can save the mail as '.html' or '.pdf' using python
from pathlib import Path
import win32com.client as win32
from datetime import date, timedelta
import os
import glob
# Create output folder
output_dir = Path.cwd()
output_dir.mkdir(parents=True, exist_ok=True)
# Connect to folder
outlook = win32.Dispatch('outlook.application').GetNamespace("MAPI")
# Connect to folder
sent_items = outlook.GetDefaultFolder(5)
# Get the required mail and store it locally
messages = sent_items.items
message = messages.GetLast()
name = str(message.subject)
message.saveas(os.getcwd()+'//'+name+".msg")
When I tried to replace .msg with .html or .pdf in the last line, then it is not working. The resultant file generated through html or pdf is displayed as special characters and not the actual .msg format