Search code examples
pythonoffice365exchange-serverexchangewebservicesoutlook.com

Accessing "Other Calendars" in exchangelib


I'm currently using exchangelib to connect to the Office365 EWS. My current scenario is that I want to access the calendars for our meeting rooms. Their calendars show up when I click the "Add Room" option from within Outlook. They also appear when I add them to the "Other Calendars" section of my Calendar view.

When I attempt to use the meeting room's e-mail address as the account, then check the Calendar, I get the following error:

exchangelib.errors.ErrorFolderNotFound: No useable default Calendar folders

So I figured that I would just access the calendar via my login, instead; as though I'm viewing the Other Calendars section in Outlook. The problem is that I can't seem to figure out how to access these calendars. I can access my own with no issue.

When I looked at the C# implementation for EWS, there is a way to search for folders and that's where you'll find the Other Calendars. I don't see anything like this in exchangelib.

To give an example:

credentials = Credentials(username='My email address', password='My password')
config = Configuration(credentials=credentials, server='outlook.office365.com', has_ssl=True)
email = # My e-mail address (I also attempted with the room's e-mail address)

account = Account(primary_smtp_address=email, credentials=credentials,
                  autodiscover=False, config=config)

for f in account.folders:
    print f

Result:

<class 'exchangelib.folders.Calendar'>
<class 'exchangelib.folders.Contacts'>
<class 'exchangelib.folders.Tasks'>
<class 'exchangelib.folders.Messages'>
<class 'exchangelib.folders.Folder'>

The 'Calendar' option cannot iterate, but the 'Folder' option can.

for f in account.folders[Folder]:
    print f

Result:

Folder (Conversation Action Settings)
Folder (Conversation History)
Folder (Files)
Folder (Journal)
Folder (Notes)
Folder (Quick Step Settings)
Folder (RSS Feeds)
Folder (Social Activity Notifications)
Folder (Yammer Root)

None of these options seem to give me what I'm looking for.

Any assistance would be greatly appreciated!

Thank you in advance

EDIT

I have found the magic of account.root.get_folders(). I can now see a very large list of folders. However, I still don't see one that appears to be usable for Other Calendars.

I've been reading about solutions that others are using in C# and came across this thread:

EWS - Access All Shared Calendars

It appears that they have some sort of search filter, but I'm unable to locate it within the exchangelib libraries.

Then I found another thread:

https://social.msdn.microsoft.com/Forums/en-US/2bfe798e-501f-421e-9a9a-76ae7eaf57c8/other-calendars-in-ews?forum=exchangesvrdevelopment

This one spoke about how the Other Calendars is a folder under the Calendars object. However, when I query account.calendar.get_folders() I come back with 0 results.


Solution

  • The No useable default Calendar folders error means that exchangelib couldn't find the default calendar folder among the folders for the account. There could be a number of reasons for that. You may still be able to find a calendar folder in Account.folders.