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.

12 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
  4. Hi Harun

    I am getting the following error when trying to run the script from my work computer.

    'Outlook Data File'
    "Your outlook data file cannot be configured."
    "C:\\Users\....(2).ost"

    Any idea what could be the problem or the solution?

    ReplyDelete
  5. Hi Prasad,
    I need python automation code to book meeting rooms in a website..

    Please help me out..

    Thanks,
    Gangadhar

    ReplyDelete
  6. hi harun,

    Im using win32com.client for sending mail from my Python script. I would like to know how to send an image in the mail body and not as attachment.
    please help.

    ReplyDelete
    Replies
    1. Hi,
      https://stackoverflow.com/questions/44544369/i-am-not-able-to-add-an-image-in-email-body-using-python-i-am-able-to-add-a-pi

      The above link should help you.
      I am also struggling for the same. Managed to embed one image in mail but still struggling to embed multiple images.

      Any help is welcome!

      Delete
  7. Hi all,

    Please help me to cancel the meeting.

    Thanks
    Devaraj

    ReplyDelete
  8. Hi,

    I am able to run the code but I am facing error if outlook application is open.

    Thanks,
    Srilekha.

    ReplyDelete
  9. Hi,

    I need to send a meeting with content in .HTMLBody to have text with other style.

    Pls!

    ReplyDelete
  10. Hi, I need to set lots of meeting for my manager, who has shared his calendar with me. This code takes default calendar only, is there a change where I can pick another calendar etc.

    ReplyDelete