四處尋找,找不到滿意的答案。有誰知道如何從Python與Outlook解析.msg文件?使用python解析outlook .msg文件
我試過用mimetools和email.parser沒有運氣。幫助將不勝感激!
四處尋找,找不到滿意的答案。有誰知道如何從Python與Outlook解析.msg文件?使用python解析outlook .msg文件
我試過用mimetools和email.parser沒有運氣。幫助將不勝感激!
這個工作對我來說:
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
請訪問以下鏈接:
[MS-OXMSG]: Outlook Item (.msg) File Format,
Read from .msg files,
Edit a saved Outlook Message File *.msg
您還可以使用Redemption及其RDOSession。 GetMessageFromMsgFile方法:
set Session = CreateObject("Redemption.RDOSession")
set Msg = Session.GetMessageFromMsgFile("c:\temp\test.msg")
MsgBox Msg.Subject
即使這是一個古老的線程,我希望這個信息可以幫助的人誰是尋找一個解決方案,以什麼的線程主題正是說。我強烈建議使用mattgwwalker in github的解決方案,這需要在外部安裝OleFileIO_PL module。
我已經試過了蟒蛇電子郵件模塊,有時並不成功解析味精文件。
所以,在這種情況下,如果你只是在文本或HTML之後,下面的代碼爲我工作。
start_text = "<html>"
end_text = "</html>"
def parse_msg(msg_file,start_text,end_text):
with open(msg_file) as f:
b=f.read()
return b[b.find(start_text):b.find(end_text)+len(end_text)]
print parse_msg(path_to_msg_file,start_text,end_text)
重要的是要注意OpenSharedItem方法需要一個絕對路徑,否則你會得到一個錯誤。 – smartexpert 2016-06-17 08:58:01
我似乎有編碼問題。你怎麼解決這個問題? – firko 2017-03-01 20:39:56