Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple mbox parser to csv in Python
import mailbox
import csv
writer = csv.writer(open("mbox-output.csv", "wb"))
for message in mailbox.mbox('file.mbox/mbox'):
writer.writerow([message['message-id'], message['subject'], message['from']])
@janewongktj
Copy link

janewongktj commented May 4, 2020

Hi David,

I'm a newbie at running python scripts.

Following the steps on this blog https://kamal.io/blog/exporting-email-threads-from-gmail-into-csv-file
led me here.

I've extracted a mbox file (about 120KB), and have tried to run this script in the same directory using Python 3.8.3rc1 IDLE, but the resulting csv file has 0bytes.

I would appreciate any pointers, I am not sure what went wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment