Python win32com获取outlook事件(约会/会议)响应状态

时间:2016-08-11 15:01:32

标签: python outlook pywin32 win32com outlook-2013

我试图通过使用Python win32com库从outlook(2013)获取事件,我已设法做到这一点,但我无法获得他们的状态(接受,暂定,拒绝)。我发现他们的状态是非常重要的,因为我当前的代码可以获取所有事件。我在网上看到存在一个AppointmentItem.ResponseStatus属性,但是我还没有设法让它使用它。谁能告诉我如何为Python实现这一目标?

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

inbox = outlook.GetDefaultFolder(9) # "9" refers to the index of a folder - in this case,
                                    # the events/appointments. You can change that number to reference
                                    # any other folder
events = inbox.Items

1 个答案:

答案 0 :(得分:0)

下面是另一种获取响应状态的方法,参考下面代码的结尾部分

如果需要,我有几行注释启用这些

更多详情 https://docs.microsoft.com/en-us/office/vba/outlook/Concepts/Forms/item-types-and-message-classes

import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
messages.Sort("[ReceivedTime]", True)

for i, msg in enumerate(messages):
    print(msg.Subject)
    print(msg.MessageClass) # use this in condition

    if msg.MessageClass=='IPM.Note':
        print('Its a Meeting')

        # Identify outlook exchange user
        if msg.SenderEmailType == "EX":
            #print(msg.Sender.GetExchangeUser().PrimarySmtpAddress)
            msg_sender = msg.Sender.GetExchangeUser().PrimarySmtpAddress
        else:
            #print(msg.SenderEmailAddress)
            msg_sender = msg.SenderEmailAddress
    elif msg.MessageClass =='IPM.Schedule.Meeting.Request':
        print('Its a Meeting')
    elif msg.MessageClass =='IPM.Schedule.Meeting.Resp.Pos':
        print('Its a Accepted Response , POS = Positive')
    elif msg.MessageClass =='IPM.Schedule.Meeting.Resp.Tent':
        print('Its a Accepted as Tentative ')
    elif msg.MessageClass == 'IPM.Schedule.Meeting.Resp.Neg':
        print('Its as Declined Meeting , Neg = Negative')

    # Check only first 45 items, change the number as per requirement
    if i > 45:
        break