使用 win32com.client 列出可用的消息属性

问题描述 投票:0回答:3

我有一个目录,其中包含数百封以 .msg 格式存储的 Outlook 电子邮件。我有一个脚本来访问特定属性,例如SenderName、Subject 等,但是脚本在某些文件上失败。经过一番调查后,失败的文件是对日历邀请的响应,失败的属性是“收件人”属性,因此必须在电子邮件和日历邀请之间以不同的方式处理此问题。所有文件都以 .msg 格式存储,因此在不打开每个单独文件的情况下,无法通过可见的方式来区分哪些文件。

我发现其他一些帖子重点关注直接访问 Outlook,而不是使用目录中保存的 .msg 文件。我目前已经对一些进行了硬编码(请参阅下面的代码),但此练习已证明属性可以根据文件类型的不同而表现不同。

我的代码示例如下。

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

有没有一种方法可以列出每个文件的所有可用属性?或者有没有一种方法来区分消息的类型,例如电子邮件、日历?

python outlook win32com
3个回答
0
投票

在访问任何消息属性之前,请检查 Class 属性(由所有 OOM 对象公开) -

olMailItem
对象的值为 43 (
MailItem
)。


0
投票
打印(消息.__dir__())

输出:


['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'] 

0
投票

尝试属性 MessageClass。通过此链接:https://learn.microsoft.com/en-us/office/vba/api/Outlook.MailItem 'IPM.Note' = 电子邮件 'IPM.Schedule.Meeting.Request' = 日历

© www.soinside.com 2019 - 2024. All rights reserved.