How do I use python to create outlook events in multiple calendars

Viewed 2047

This is the code I've been using. It works when I want to create an appointment, but only in my main calendar. Do any of you know how to create the appointments in a secondary calendar?

import win32com.client
from win32com.client import Dispatch
outlook = win32com.client.Dispatch("Outlook.Application")


def sendMeeting():
  appt = outlook.CreateItem(1) # AppointmentItem
  appt.Start = "2021-5-28 16:10" # yyyy-MM-dd hh:mm
  appt.Subject = "Fake meeting"
  appt.Duration = 30 # In minutes (60 Minutes)
  appt.Location = "The bat cave"

  appt.Save()
  appt.Send()

1 Answers

Do you mean a secondary Exchange account in the profile? Or a delegate Exchange mailbox? In the former case, open the store from the Namespace.Stores collection, open the Calendar folder using Store.GetDefaulFolder(olFolderCalendar), create new item using MAPIFolder.Items.Add. In the latter case, you can use Namespace.GetSharedDefaultFolder(Recipient, olFolderCalendar) (where Recipient can be retrieved from Namespace.CreateRecipient).

If it is a subfolder in your primary store, you can access it from its parent folder and call MAPIFolder.Items.Add. E.g. if it is a subfolder of your default Calendar folder, use outlook.Session.GetDefaultFolder(olFolderCalendar).Folders.Item("The name"). If it is on the same level as your Calendar folder, use outlook.Session.GetDefaultFolder(olFolderCalendar).Parent.Folders.Item("The name").

Related