1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > python如何读pst文件_python - 从win32或pypff读取PST文件 - SO中文参考 - www.soinside.com...

python如何读pst文件_python - 从win32或pypff读取PST文件 - SO中文参考 - www.soinside.com...

时间:2021-04-15 15:46:26

相关推荐

python如何读pst文件_python - 从win32或pypff读取PST文件 - SO中文参考 - www.soinside.com...

这是我想为自己的应用程序做的事情。我能够从这些来源整理出一个解决方案:

上面的第三个链接应提供有关可用属性和各种项目类型的更多详细信息。我的解决方案仍然需要连接到Outlook应用程序,但是对用户来说应该是透明的,因为在try / catch / finally块中使用pst存储区会自动将其删除。我希望这可以帮助您走上正确的轨道!import win32com.client

def find_pst_folder(OutlookObj, pst_filepath) :

for Store in OutlookObj.Stores :

if Store.IsDataFileStore and Store.FilePath == pst_filepath :

return Store.GetRootFolder()

return None

def enumerate_folders(FolderObj) :

for ChildFolder in FolderObj.Folders :

enumerate_folders(ChildFolder)

iterate_messages(FolderObj)

def iterate_messages(FolderObj) :

for item in FolderObj.Items :

print("***************************************")

print(item.SenderName)

print(item.SenderEmailAddress)

print(item.SentOn)

print(item.To)

print()

print(item.BCC)

print(item.Subject)

count_attachments = item.Attachments.Count

if count_attachments > 0 :

for att in range(count_attachments) :

print(item.Attachments.Item(att + 1).Filename)

Outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

pst = r"C:\Users\Joe\Your\PST\Path\example.pst"

Outlook.AddStore(pst)

PSTFolderObj = find_pst_folder(Outlook,pst)

try :

enumerate_folders(PSTFolderObj)

except Exception as exc :

print(exc)

finally :

Outlook.RemoveStore(PSTFolderObj)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。