【发布时间】:2021-05-24 13:40:17
【问题描述】:
我正在尝试自动化一些 python 代码,该代码将自动保存某些电子邮件中具有特定标题的一些附件。
以下是我目前拥有的:
import win32com.client as client
outlook = client.Dispatch('Outlook.Application')
namespace = outlook.GetNameSpace('MAPI')
inbox = namespace.GetDefaultFolder(6)
target_subject = 'Testing attachment'
mail_items = [item for item in inbox.Items if item.Class == 43]
filtered = [item for item in mail_items if item.Subject == target_subject]
if len(filtered) != 0:
target_email = filtered[0]
if target_email.Attachments.Count > 0:
attachments = target_email.Attachments
save_path = 'C:'
for file in attachments:
file.SaveAsFile(save_path.format(file.FileName))
但是我似乎遇到了权限错误?
com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft Outlook', "Cannot save the attachment. You don't have appropriate permission to perform this operation.", None, 0, -2147024891), None)
不知道如何解决这个问题,我是管理员等。
我还想知道实际在线部署并运行它需要进行哪些更改,即我没有传递任何凭据,因为它是本地的,如果独立运行,我希望它每 7 天访问一次我的收件箱或所以并从这个特定的电子邮件下载这个特定的附件。
任何帮助将不胜感激。
谢谢!
【问题讨论】:
标签: python outlook email-attachments pywin32 win32com