Matteo Devigili
Matteo Devigili

Reputation: 21

Cannot access Exchange Public Folder Calendar with c# ExchangeWebServics

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.

https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-authenticate-an-ews-application-by-using-oauth

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);

Upvotes: 0

Views: 416

Answers (1)

Matteo Devigili
Matteo Devigili

Reputation: 21

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]");

Upvotes: 0

Related Questions