Extract attachments from Outlook .msg files.
Low maintenance activity. Last release 22 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and recent releases.
Consider insteadextract-msgPythie’s Index: 7611.1M downloads/moCompare →
pip install python-oxmsgpython-oxmsg
Parse Outlook MSG (.msg) files to extract email messages and attachments.
The target use case is extracting Outlook message text and accessing attachments. There is no support for modifying messages or creating them from scratch. In addition to message text, other message properties such as sent-date, etc. are also accessible.
Documentation
Documentation for this project is on GitHub Pages.
Installation
pip install python-oxmsg
Occasionally it can be useful to install from a GitHub branch, perhaps to try out a version that has not yet been released. This command would install from the develop branch:
pip install git+https://github.com/scanny/python-oxmsg@develop
Usage
>>> from oxmsg import Message
>>> msg = Message.load("message.msg")
>>> msg.message_class
'IPM.Note'
>>> msg.attachment_count
1
>>> attachment = msg.attachments[0]
>>> attachment.attached_by_value # -- attachment bytes only available when True --
True
>>> attachment.file_name
'q1-objectives.pptx'
>>> attachment.mime_type
'application/vnd.openxmlformats-officedocument.presentationml.presentation'
>>> attachment.size
96407
>>> attachment.last_modified.isoformat()
'2023-11-18T16:08:17+00:00'
>>> with open(attachment.file_name, "wb") as f:
... f.write(attachment.file_bytes)
CLI
python-oxmsg includes a CLI that may be useful for diagnostic purposes.
$ oxmsg
Usage: oxmsg [OPTIONS] COMMAND [ARGS]...
Utility CLI for `python-oxmsg`.
Provides the subcommands listed below, useful for exploratory or diagnostic
purposes.
Options:
--help Show this message and exit.
Commands:
dump Write a summary of the MSG file's properties to stdout.
storage Summarize low-level "directories and files" structure of MSG...
The dump sub-command displays all properties available in the message along with the
PID and PTYP information required to access those properties from a object.