【问题标题】:Python win32com get outlook event (appointment/meeting) response statusPython win32com 获取outlook事件(约会/会议)响应状态
【发布时间】:2016-08-11 15:01:31
【问题描述】:

我正在尝试使用 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

【问题讨论】:

    标签: python outlook pywin32 win32com outlook-2013


    【解决方案1】:

    来自GetDefaultFolder(9) 的项目是AppointmentItems,它们的属性可以在这里找到:https://msdn.microsoft.com/en-us/library/office/ff862177.aspx#Anchor_4

    outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
    calendar = outlook.GetDefaultFolder(9)
    appointments = calendar.Items
    for appointment in appointments:
        print(appointment.ResponseStatus)
    

    ResponseStatuses 以整数形式返回,可以使用此表将其转换为状态:https://msdn.microsoft.com/en-us/library/office/ff868658.aspx

    【讨论】:

      【解决方案2】:

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

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

      更多细节 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 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-21
        • 2010-12-14
        • 2016-09-25
        • 2015-06-21
        相关资源
        最近更新 更多