Mic*_*ael 27 python email outlook
环顾四周,找不到满意的答案.有谁知道如何用Outlook解析outlook中的.msg文件?
我尝试过使用mimetools和email.parser没有运气.非常感谢帮助!
Bre*_*rds 34
这对我有用:
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
Run Code Online (Sandbox Code Playgroud)
Vla*_*kin 11
我使用msg-extractor
Matt Walker的实用工具成功地从MS Outlook文件(.msg)中提取了相关字段。
pip install extract-msg
Run Code Online (Sandbox Code Playgroud)
请注意,可能需要安装其他模块,在我的情况下,需要安装imapclient:
pip install imapclient
Run Code Online (Sandbox Code Playgroud)
import extract_msg
f = r'MS_Outlook_file.msg' # Replace with yours
msg = extract_msg.Message(f)
msg_sender = msg.sender
msg_date = msg.date
msg_subj = msg.subject
msg_message = msg.body
print('Sender: {}'.format(msg_sender))
print('Sent On: {}'.format(msg_date))
print('Subject: {}'.format(msg_subj))
print('Body: {}'.format(msg_message))
Run Code Online (Sandbox Code Playgroud)
MsgExtractor实用程序中还有许多其他优点,有待探索,但这很好。
我不得不注释掉文件C:\ Anaconda3 \ Scripts \ ExtractMsg.py中的第3至8行:
#"""
#ExtractMsg:
# Extracts emails and attachments saved in Microsoft Outlook's .msg files
#
#https://github.com/mattgwwalker/msg-extractor
#"""
Run Code Online (Sandbox Code Playgroud)
错误消息为:
line 3
ExtractMsg:
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
阻塞了这些行之后,错误消息消失了,代码正常运行了。
尽管这是一个旧线程,但我希望这些信息可以帮助那些正在寻找线程主题确切内容的解决方案的人。我强烈建议使用github 中 mattgwwalker的解决方案,该解决方案需要外部安装OleFileIO_PL 模块。
归档时间: |
|
查看次数: |
44226 次 |
最近记录: |