Phil
Phil

Reputation: 71

Create appointment in shared calendar using python

I prefer not to show my inexperience by posting on here, but this is driving me insane.

I want to add an appointment to a shared calendar. I'm close but can't figure out how to tell it save the item to the shared calendar and not my own default calendar.

import win32com.client

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

recipient = namespace.createRecipient("[email protected]")
resolved = recipient.Resolve()
sharedCalendar = namespace.GetSharedDefaultFolder(recipient, 9).Folders("Bookings")

appointment = outlook.CreateItem(1) # 1=outlook appointment item
appointment.Start = '2017-07-17 08:00'
appointment.Subject = "Test booking"
appointment.Duration = 60
appointment.Save()

I have a workaround of replacing appointment.save() with :

appointment.Move(sharedCalendar)

and while this does the job, its not the correct way and doesn't help me with working out the next script which needs to read the appointments from the shared calendar.

Upvotes: 1

Views: 3332

Answers (1)

Phil
Phil

Reputation: 71

I needed to use a different method when setting up the appointment object, which allowed me to use the sharedFolder object:

appointment = sharedCalendar.Items.Add(1)

Upvotes: 3

Related Questions