I'm trying to read a public folder calendar events with no success. I'm authenticating using App-only as per microsoft documentation and I am able to obtain an access token.
I Created the a public folder calendar in the Exchange admin center, created a test event on it, and enabled it's email that came out something like this: [email protected]
Below here is the part of code that gives the exception: "The SMTP address has no mailbox associated with it."
I created a public folder mailbox, but I cannot find anywhere on the exchange admin center where to associate public folder mailboxes to public folder.
calendarFolderId = new FolderId(WellKnownFolderName.Calendar,CalendarConfig.CalendarEmail);
FolderView folderView = new FolderView(1);
var folders = await ewsClient.FindFolders(calendarFolderId, folderView);
Turns out the problem was that I was impersonating the wrong user while configuring the ewsClient. In ImpersonatedUserId I was using the public folder mailbox. I had to use another User mailbox that had access to the public folder.
ewsClient = new ExchangeService();
ewsClient.Url = new Uri(config.ServiceId);
ewsClient.Credentials = new OAuthCredentials(authResult.AccessToken);
ewsClient.ImpersonatedUserId =
new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "[email protected]");
to
ewsClient = new ExchangeService();
ewsClient.Url = new Uri(config.ServiceId);
ewsClient.Credentials = new OAuthCredentials(authResult.AccessToken);
ewsClient.ImpersonatedUserId =
new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "[email protected]");