【问题标题】:how save or extract Attachments file from MSG file with python? [duplicate]如何使用 python 从 MSG 文件中保存或提取附件文件? [复制]
【发布时间】:2020-04-29 15:38:48
【问题描述】:

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

【问题讨论】:

标签: python outlook attachment email-attachments


【解决方案1】:

要从 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

完成!

【讨论】:

  • 我们可以关闭文件吗?我收到此错误:“”我们无法打开“HVB 曲线 27-1-2021.msg”。可能文件已经打开,或者您没有权限”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-31
  • 1970-01-01
  • 2022-11-10
相关资源
最近更新 更多