3

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?

DeltaKilo
  • 113
  • 3
  • 12

2 Answers2

0

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

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
0
print(message.__dir__())

Output:


['TaskStartDate', '_username_', '_print_details_', '__lt__', '__doc__', 'ReceivedByEntryID', '_FlagAsMethod', 'MessageClass', '_get_good_single_object_', 'BCC', 'UserProperties', '_lazydata_', '__weakref__', 'Display', 'ReminderTime', 'ReminderSoundFile', 'RetentionPolicyName', 'InternetCodepage', '__ne__', '_mapCachedItems_', 'Forward', 'Sent', 'SaveSentMessageFolder', 'ConversationTopic', '__reduce_ex__', '__call__', 'MarkForDownload', 'IsMarkedAsTask', 'ReplyAll', '__LazyMap__', 'Invoke', 'ToDoTaskOrdinal', 'ClearTaskFlag', '_enum_', 'PermissionService', '__hash__', '__eq__', 'RemoteStatus', 'DeleteAfterSubmit', '__repr__', 'Session', 'AddRef', 'Actions', 'Subject', '__getattribute__', 'SenderName', '__subclasshook__', '__setattr__', 'Copy', 'HTMLBody', 'ReplyRecipientNames', 'VotingResponse', 'Reply', 'Links', 'Companies', '_find_dispatch_type_', '__gt__', 'OutlookVersion', '_UpdateWithITypeInfo_', 'Saved', 'ReminderOverrideDefault', 'VotingOptions', 'Conflicts', '_make_method_', 'SendUsingAccount', '_oleobj_', '__len__', 'Close', 'Move', '_proc_', 'Mileage', 'Permission', '_dir_ole_', 'LastModificationTime', 'ReceivedByName', 'ItemProperties', 'IsIPFax', 'FlagStatus', '__reduce__', 'GetTypeInfo', 'ConversationID', 'Sender', '__init__', '__ge__', 'DownloadState', 'PermissionTemplateGuid', 'Application', 'SaveAs', 'TaskCompletedDate', 'AutoResolvedWinner', 'SentOnBehalfOfName', 'GetIDsOfNames', 'NoAging', '_LazyAddAttr_', 'TaskDueDate', '_get_good_object_', 'RTFBody', 'Size', 'CreationTime', 'AutoForwarded', 'Class', 'Sensitivity', 'Importance', '_ApplyTypes_', '__new__', '__int__', 'CC', 'ExpiryTime', 'To', 'ConversationIndex', '__AttrToID__', 'BodyFormat', 'OutlookInternalVersion', 'AlternateRecipientAllowed', 'ReadReceiptRequested', 'PropertyAccessor', 'RetentionExpirationDate', 'EntryID', 'Parent', '_wrap_dispatch_', 'Body', '__str__', '_NewEnum', '__bool__', '__dict__', '__format__', 'EnableSharedAttachments', 'FlagRequest', 'ShowCategoriesDialog', '__getitem__', 'HasCoverSheet', 'Attachments', '_unicode_to_string_', '_Release_', '__class__', 'GetConversation', 'FlagDueBy', '__setitem__', '__delattr__', '__module__', '__dir__', 'Release', 'UnRead', 'ReceivedOnBehalfOfEntryID', '_builtMethods_', '__le__', 'DeferredDeliveryTime', 'BillingInformation', 'ReminderPlaySound', 'SenderEmailAddress', 'QueryInterface', 'Categories', 'Save', 'SenderEmailType', 'Recipients', 'Delete', 'MAPIOBJECT', 'Send', 'FlagIcon', '__getattr__', 'SentOn', 'AddBusinessCard', 'ClearConversationIndex', 'GetTypeInfoCount', 'GetInspector', 'IsConflict', 'ReplyRecipients', 'PrintOut', 'ReminderSet', 'ReceivedTime', '__init_subclass__', '__sizeof__', 'FormDescription', '_olerepr_', 'OriginatorDeliveryReportRequested', 'MarkAsTask', 'ReceivedOnBehalfOfName', 'RecipientReassignmentProhibited', 'Submitted', 'TaskSubject'] 
Sarah
  • 1,361
  • 2
  • 14
  • 20