I have a directory with hundreds of Outlook emails stored in .msg format. I have a script to access specific attributes, e.g. SenderName, Subject etc, however the script fails upon certain files. After some investigation, the failing files are responses to calendar invites, and the attribute that fails is the 'To' attribute, so this must be handled differently between emails and calendar invites. All files are stored in .msg format so there is no visible way to distinguish which ones are which without opening each individual file.
Some other posts I've found focus on accessing Outlook directly, not using saved .msg files in a directory. I've currently hardcoded some (see code below), but this exercise has proven attributes can behave differently depending on the file type.
A sample of the code I have is below.
for eachFile in msgList:
filePath = outDir + "\\" + eachFile
msg = outlook.OpenSharedItem(filePath)
print msg.ReceivedTime
print msg.Subject
print msg.Body
print msg.To
print msg.Size
print msg.Attachments
Is there a method to list all available attrubites for each file? Or is there a method to distinguish the type of message, e.g. email, calendar?
Before accessing any message properties, check the Class property (exposed by all OOM objects) - it will be 43 (olMailItem) for the MailItem object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With