Com Error In Downloading Attachment From Outlook Through Win32com
import win32com.client import os outlook = win32com.client.Dispatch('Outlook.Application').GetNamespace('MAPI') inbox = outlook.GetDefaultFolder(6) messages = inbox.Items mess
Solution 1:
You code assumes every message in the Inbox folder has at least one attachment. That assumption is clearly invalid.
Either check that Attachments.Count > 0
or actually loop over the attachments collection instead of simply retrieving the very first attachment (attachments.Item(1)
) whether the message has attachments or nor.
Also keep in mind messages.GetFirst()
will return some random item since you never sort the collection in any way. Most likely you will get the oldest created message. Do not assume that the sort order of the messages shown by Outlook will be the same as what you have.
Post a Comment for "Com Error In Downloading Attachment From Outlook Through Win32com"