Just a quickie since it comes up sometimes and I keep needing to remember the magic search terms. Sometimes we get given msg files, and I don't want to load them into Outlook (plus my DTD is on a Mac and Outlook for Mac won't read 'em anyway). Mostly I'm just interested in the headers, so today I did a really nasty script. First you need the extract-msg package, which you can install with pip. Then:

import extract_msg
f = r'the.msg'
msg=extract_msg.Message(f)
for k in msg.headerDict.keys():
    print(f"{k}\n{msg.headerDict[k]}\n\n")

Published

Category

Technology

Contact