我正在尝试自动化一些 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 天左右访问我的收件箱并下载此特定电子邮件中的特定附件。
任何帮助将不胜感激。
谢谢!