简体   繁体   中英

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: CalendarName@MSDx123456.onmicrosoft.com

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, "publicFolderMail@MSDx123456.onmicrosoft.com");

to

        ewsClient = new ExchangeService();
        ewsClient.Url = new Uri(config.ServiceId);
        ewsClient.Credentials = new OAuthCredentials(authResult.AccessToken);
        ewsClient.ImpersonatedUserId =
            new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "Impersonated-User-Mailbox@MSDx123456.onmicrosoft.com");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM