Reputation: 151
I'm trying to loop through a number of email archives, and find various things with different properties. I currently have the following code, which successfully loads the folder, and starts looping through it. However, it seems to fail when the next item it comes to is an appointment (I guess an item with type 'AppointmentItem'), presumably because AppointmentItems don't have a 'To' attribute (the error is 'AttributeError: .to')
I'm quite happy to skip all the AppointmentItem objects, but I can't work out how to distinguish programmatically which are MailItems and which are something else.
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
email_list = []
archive_list = ['Archive1']
for folder in outlook.Folders:
if folder.name in archive_list:
sent = folder.Folders['Sent Items'].items
for message in sent:
print (message.to,message.subject)
Upvotes: 0
Views: 1444
Reputation: 49405
You can use the MessageClass
property of Outlook items. See Item Types and Message Classes for more information.
Upvotes: 2