Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing outlook .msg files with python

Looked around and couldn't find a satisfactory answer. Does anyone know how to parse .msg files from outlook with Python?

I've tried using mimetools and email.parser with no luck. Help would be greatly appreciated!

like image 398
Michael Avatar asked Oct 12 '14 05:10

Michael


People also ask

How do I open an Outlook MSG file?

You can open an MSG file with Microsoft Outlook in Windows simply by double-clicking the file. If Outlook is not set as the default application for opening MSG files, you can right-click the file and choose Outlook to open the MSG file.

How do I open a .msg file in Outlook without Outlook?

To open an MSG file for free, you can use Outlook.com or the Outlook Web version. However, if you do not want to use Outlook, you can use the SysTools MSG Viewer. Apart from that, you can also use the Zamzar tool to convert MSG to PDF.


1 Answers

This works for me:

import win32com.client outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") msg = outlook.OpenSharedItem(r"C:\test_msg.msg")  print msg.SenderName print msg.SenderEmailAddress print msg.SentOn print msg.To print msg.CC print msg.BCC print msg.Subject print msg.Body  count_attachments = msg.Attachments.Count if count_attachments > 0:     for item in range(count_attachments):         print msg.Attachments.Item(item + 1).Filename  del outlook, msg 

Please refer to the following post regarding methods to access email addresses and not just the names (ex. "John Doe") from the To, CC and BCC properties - enter link description here

like image 138
Brent Edwards Avatar answered Sep 20 '22 17:09

Brent Edwards