0

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?

0

Before accessing any message properties, check the Class property (exposed by all OOM objects) - it will be 43 (olMailItem) for the MailItem object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.