1. Products
  2.   Email
  3.   Python
  4.   MSG-Extractor
 
  

Open Source Python Library for Outlook® MSG Files

Read & parse Microsoft® Outlook MSG emails via Python.

What is MSG-Extractor Library?

MSG-Extractor gives software developers the ability to process Microsoft Outlook MSG files from Python apps. It automates the extraction of key email data such as from, to, cc fields as well as subject, body, date, and attachments. The Python MSG library also supports features such as reading an email message, extracting attachments, embedding MSG files, command-line arguments and save attachments to custom location. 

Previous Next

How to Install MSG-Extractor?

Install MSG-Extractor via PyPi

 pip install extract-msg 

Open MSG File via Python

The MSG-Extractor library allows Python developers to access & read the contents of Outlook MSG files. You can access the email recipient addresses as well as view email messages & attachments. By using the following lines of code, you can easily read messages via python.

Open MSG File

  1. Open existing MSG file using extract_msg.Message() method and pass file name as parameter
  2. Get and print the sender of the email using msg.sender property
  3. Get and print the date of the email using msg.date property
  4. Get and print the subject of the email using msg.subject property
  5. Get and print the message body of the email using msg.body property

Python Dependency for MSG-Extractor

f = r'MS_Outlook_file.msg' 
# open message
msg = extract_msg.Message(f)
# print sender name
print('Sender: {}'.format(msg.sender))
# print date
print('Sent On: {}'.format(msg.date))
# print subject
print('Subject: {}'.format(msg.subject))
# print body
print('Body: {}'.format(msg.body))

Save Attachments & Messages

MSG-Extractor library enables the extraction of attachments from Outlook MSG files. The API provides the functionality to scan all the email messages stored in MSG and displays the list of messages that it finds. Users can select the attachments of their choice and save them to a chosen folder. It also allows users to delete unwanted files.

 English