I am fairly new to Python, and I am trying to export key data points from .msg files into a single .csv
I've followed guidance from this thread: Parsing outlook .msg files with python
This, combined with using the csv module, has allowed me to export the results from a single .msg file, but I don't know how to program it to parse through all the .msg files in the same folder, and insert the results of each file in the subsequent rows in the csv file.
import extract_msg
import csv
f = r'\Email.msg'
msg = extract_msg.Message(f)
msg_sender = msg.sender
msg_date = msg.date
msg_subj = msg.subject
msg_message = msg.body
with open(r'\Email.csv', mode='w') as file:
fieldnames = ['Subject', 'Date', 'Sender']
writer = csv.DictWriter(file, fieldnames=fieldnames)
writer.writeheader()
writer.writerow({'Subject': msg_subj, 'Date': msg_date, 'Sender': msg_sender})