【发布时间】:2020-07-20 00:38:06
【问题描述】:
我尝试使用我找到的这个脚本here。我想要做的是给出一些主题行或电子邮件,我将下载并保存附件。
这是我使用的代码:
import datetime
import os
import win32com.client
path = os.path.expanduser("//cottonwood//users///MyDocuments//Projects//outlook crawler")
today = datetime.date.today()
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
def saveattachemnts(subject):
for message in messages:
if message.Subject == subject and message.Unread or message.Senton.date() == today:
# body_content = message.body
attachments = message.Attachments
attachment = attachments.Item(1)
for attachment in message.Attachments:
attachment.SaveAsFile(os.path.join(path, str(attachment)))
if message.Subject == subject and message.Unread:
message.Unread = False
break
saveattachemnts("Snarf")
我收到此错误:
File "<COMObject <unknown>>", line 2, in Item
pywintypes.com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft Outlook', 'Array index out of bounds.', None, 0, -2147352567), None)
Outlook 电子邮件是工作电子邮件,它是 Microsoft Outlook 2010。
我的问题是如何从 Microsoft Outlook 下载和保存附件。
【问题讨论】:
-
请澄清您的问题到底是什么。有没有调试过?
-
@AMC 我确实尝试过调试它,但我不确定出了什么问题。我编辑了我的帖子以包含一个问题。
-
我的问题是如何从 Microsoft Outlook 下载和保存附件。 看看这个:stackoverflow.com/questions/39656433/…
-
@AMC 不,它没有解决我遇到的错误。
标签: python email outlook email-attachments win32com