import win32com.client
import os
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
message = messages.GetFirst()
attachments = message.Attachments
for i in messages:
if(i.UnRead==True):
attachment = attachments.Item(1)
attachment.SaveASFile(os.getcwd() + '\\' + str(attachment))
else:
pass
I am getting below error when trying to download the attachment from outlook
Error: com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft Outlook', 'Array index out of bounds.', None, 0, -2147352567), None)