I know that this has been asked here several times, and I have tried what has apparently worked for others...I have more than 1000 Outlook .msg files with .xlsx file attachments stored in folders on my desktop and I only need to extract the .xlsx files to combine into a single dataframe.
I have tried the VBA macro, and Python [Win32] (Parsing outlook .msg files with python) and msg-extractor. The best I can do is to extract a single attachment from a single .msg file
Any advice is greatly appreciated. Thank you!
import argparse
import csv
import os as os
import pathlib
import sys
from datetime import date, datetime, timedelta, tzinfo
from enum import Enum, IntEnum
from tempfile import mkstemp
import dateutil.parser as duparser
from dateutil.rrule import rrulestr, rruleset
import pywintypes
import pytz
import win32com.client
path = r'C:\Users\Me\Desktop\MyFiles\feb_2018'
files = [f for f in os.listdir(path) if '.msg' in f]
print (files)
for file in files:
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
msg = outlook.OpenSharedItem(os.path.join(path, file))
att=msg.Attachments
for i in att:
i.SaveAsFile(os.path.join(path, i.FileName))