如何使用 python 从 MSG 文件中保存或提取附件文件?

how save or extract Attachments file from MSG file with python?

如何从 python 中的 MSG 文件下载、保存或提取附件文件? 有很多用于提取发件人姓名或...的库,但用于提取 msg 文件的库不起作用。

要从 Outlook 的 MSG 文件中提取文件,请使用此代码:

import win32com.client,os
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
msg = outlook.OpenSharedItem('C:/Users/aa/test.msg')
for att in msg.Attachments:
        print(att.FileName)
        print(msg.Attachments.Count)
        att.SaveASFile(os.path.join(save_folder, str(att.FileName))) # save_folder is that folder for save Attachments files  example: C:/Users/aa/extract

完成!