Python win32com get outlook event (appointment/meeting) response status
Asked Answered
M

2

5

I'm trying to get events from outlook(2013) by using the Python win32com library, I have managed to do this, however I have not been able to get their status (Accepted, tentative, declined). It's important that I find out their status as the my current code gets all events. I read online that there exists an AppointmentItem.ResponseStatus Property, however I haven't managed to make it work using this. Can anyone tell me how I can achieve this for 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
Mosby answered 11/8, 2016 at 15:1 Comment(0)
R
9

Items from GetDefaultFolder(9) are AppointmentItems and their properties can be found here: 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 are returned as integers, which can be translated to statuses with this table: https://msdn.microsoft.com/en-us/library/office/ff868658.aspx

Rome answered 23/2, 2017 at 23:7 Comment(0)
S
0

Below is the another way to get the status of response, refer end part of the below code

I have few lines commented enable those if required

More details https://learn.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 
Samples answered 14/4, 2021 at 22:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.