Tuesday, 31 January 2012

Python: Make a Meeting Request / an Appointment in MS Outlook

Have you ever wanted to automate the setting up of meeting requests and/or appointments on MS Outlook from python language?
Here are the tools/packages used for the below scripts.
  1. MS Outlook 20xx
  2. Python 2.x
  3. Python for Windows extension (pywin32 build 216)
Setting up an Appointment

import win32com.client
oOutlook = win32com.client.Dispatch("Outlook.Application")
appt = oOutlook.CreateItem(1) # 1 - olAppointmentItem
appt.Start = '2012-01-28 17:00'
appt.Subject = 'Follow Up Meeting'
appt.Duration = 15
appt.Location = 'Office - Room 132A'
appt.Save()
print "Done"

This will place a appointment in your default account setup in MS Outlook

Setting up a Meeting Request

Meeting request in outlook are slight variations of appointments. So first an appointment has to be created and convert it to appointment, buy setting meeting status property.

import win32com.client
oOutlook = win32com.client.Dispatch("Outlook.Application")
appt = oOutlook.CreateItem(1) # 1 - olAppointmentItem
appt.Start = '2012-01-28 17:00'
appt.Subject = 'Follow Up Meeting'
appt.Duration = 15
appt.Location = 'Office - Room 132A'
appt.MeetingStatus = 1 # 1 - olMeeting; Changing the appointment to meeting
#only after changing the meeting status recipients can be added
appt.Recipients.Add("recipient1@somedomain.com")
appt.Save()
appt.Send()
print "Done"

Let me know if you want to automatically accept certain meeting requests automatically though similar python script as above.

Here is the story for this post. One of my former colleague and friend was spending about 45 mins every week setting up meeting requests with few participants based on some conditional fulfillment, which was cumbersome and errorprone. So he was looking for a way to automate it and approached me.

3 comments:

  1. Thank you so much Harun.The code works really great. Once again you proved that you are a python genius.

    ReplyDelete
  2. Great code, great example!

    How about canceling a meeting request?

    Changing the line appt.MeetingStatus = 1 to appt.MeetingStatus = 5
    sends out a email cancel request however the meeting is not deleted from the calender.

    Thanks,
    Bruce

    ReplyDelete
  3. Hi Harun, well I have a scenario that i'm trying to resolve and seems like u'r the man I should talk to about it. So a new team has come to work on our floor and they are keeping the meeting rooms occupied all the times. So i am thinking about a script that can find through and make bookings among the available rooms. the input parameters would be seat_no(can be 4 seter or 8 seter rooms - this is a non negotible criteria, if i am looking for 4 seter i'm ok if a 8 seter gets booked but not the other way around), duration(if duration is 1 hr and no room is available system should check if 2 rooms are available for 30 min each and book both for 30 min[30 min is the minimum] each .. etc). and rooms should belong to a list of rooms(coz otherwise sitting in India i'll end up booking rooms in China or USA) that should be used.

    Any ideas or code would be highly appreciated man.
    -Sandeep

    ReplyDelete