使用python解析Outlook .msg文件 [英] Parsing outlook .msg files with python

查看:403
本文介绍了使用python解析Outlook .msg文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环顾四周,找不到满意的答案.有谁知道如何使用Python从Outlook解析.msg文件?

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

我曾经尝试过使用mimetools和email.parser,但是没有运气.帮助将不胜感激!

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

推荐答案

这对我有用:

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

关于访问电子邮件地址的方法,请参阅以下帖子,而不仅仅是收件人,抄送和密件抄送属性中的电子邮件地址(例如"John Doe")(

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

这篇关于使用python解析Outlook .msg文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆