2

I can get all appointments from my main calendar, like this:

def getCalendarEntries():
    Outlook = win32com.client.Dispatch("Outlook.Application")
ns = Outlook.GetNamespace("MAPI")
appointments = ns.GetDefaultFolder(9).Items
appointments.Sort("[Start]")
appointments.IncludeRecurrences = "True"
begin = datetime.date.today()
end = begin + datetime.timedelta(days = 100);
restriction = "[Start] >= '" + begin.strftime("%m/%d/%Y") + "' AND [End] <= '" +end.strftime("%m/%d/%Y") + "'"
restrictedItems = appointments.Restrict(restriction)
events={'Start':[],'End':[],'Organizer':[],'Subject':[],'Duration':[]}
for a in restrictedItems:
    events['Start'].append(a.Start)
    events['End'].append(a.End)
    events['Organizer'].append(a.Organizer)
    events['Subject'].append(a.Subject)
    events['Duration'].append(a.Duration)
return events

And I can save events into my main calendar, like this:

 def addevent(start, subject, duration):
Outlook = win32com.client.Dispatch("Outlook.Application")
appointment = Outlook.CreateItem(1) # 1=outlook appointment item
appointment.Start = start
appointment.Subject = subject
appointment.Duration = duration
appointment.Save()

My issue is that I don't know how to connect to another calendar folder. I don't want the "DefaultFolder" but a specific one. I would be really greatful if someone could help me.

MajinBoo
  • 307
  • 1
  • 2
  • 10

3 Answers3

0

Found the answer myself. One has to replace

appointments = ns.GetDefaultFolder(9).Items

with

recipient = ns.createRecipient("foo@outlook.com") 
resolved = recipient.Resolve()
appointments = ns.GetSharedDefaultFolder(recipient, 9).Items
MajinBoo
  • 307
  • 1
  • 2
  • 10
0

another way of read Items in another calender with subfolders i.e. \abc@outlook.com\Calendar\Work_Exchange could be:

privateol = ns.Folders('abc@outlook.com')
privatecal = privateol.Folders('Calendar')
privatesubfolder = privatecal.Folders('Work_Exchange')

What i don't know is, how to write in this specific Subfolder, so if anyone wants to provide...

lg

Edit: to write to the specific subfolder, one has to replace appointment.Save() with appointment.Move(privatesubfolder)

maybe it's not the best solution, but it works

gafl
  • 1
  • 1
0

Had exact the same issue but got brilliant help: use the Items.Add() Method and it perfectly works in whatever folder you are in. See here: Create Outlook appointment in subfolder/subcalendar with python