EWS Impersonation for emails and conference room booking

D Aqui Joseph 1 Reputation point
2020-08-24T20:24:37.97+00:00

I created an on-prem app that will book conference rooms by first querying the available rooms as a service account (AD) and then hen it comes time for booking the app will impersonate the user who is logged in and send an email to the conference room and people invited. Now that some users in my company have had their email account moved to O365, they can still see the rooms available as the account is on-prem and in O365, but when it comes time in the code to impersonate the user, when it is an O365 account, to send the email to the conference room or invited users, I get the following error:

[ServiceResponseException: The account does not have permission to impersonate the requested user.]
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ProcessWebException(WebException webException) +1322
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request) +138
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request) +535
Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest1.Execute() +42 Microsoft.Exchange.WebServices.Data.ExchangeService.InternalCreateItems(IEnumerable1 items, FolderId parentFolderId, Nullable1 messageDisposition, Nullable1 sendInvitationsMode, ServiceErrorHandling errorHandling) +142
Microsoft.Exchange.WebServices.Data.Item.InternalCreate(FolderId parentFolderId, Nullable1 messageDisposition, Nullable1 sendInvitationsMode) +271
Microsoft.Exchange.WebServices.Data.Appointment.Save(FolderId destinationFolderId, SendInvitationsMode sendInvitationsMode) +91
booknow.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\RoomBook\booknow.aspx.cs:1006
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +11760440
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +150
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5028

And this is the code that causes it:

appointment.Save(new FolderId(WellKnownFolderName.Calendar, email_addr), SendInvitationsMode.SendToAllAndSaveCopy);

Any guidance would be appreciated.

Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,327 questions
Microsoft Exchange Hybrid Management
Microsoft Exchange Hybrid Management
Microsoft Exchange: Microsoft messaging and collaboration software.Hybrid Management: Organizing, handling, directing or controlling hybrid deployments.
1,864 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,333 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Andy David - MVP 140.8K Reputation points MVP
    2020-08-24T21:22:58.147+00:00

    Have you enabled Impersonation for the service account to the Office 365 mailboxes as well?
    Your code will have to account for the mailboxes now in 365.

    0 comments No comments

  2. KyleXu-MSFT 26,206 Reputation points
    2020-08-25T09:19:11.407+00:00

    The using of EWS is related with Exchange development which doesn't supported in Q&A so far. I would suggest you post this question in Exchange development forum or open a ticket to Microsoft. It will help you solve this question.

    Here are my suggestion which may be useful to you:

    The account does not have permission to impersonate the requested use

    From this error message we can see that there was lacking of permission to impersonation. Since this mailbox is migrated to Exchange online, I would suggest you to try to given permission for this mailbox from Exchange online again.

    I also suggest you try to give the impersonation permission to a Exchange online rather than migrated mailbox, then check whether your application could impersonation this mailbox. If it cannot impersonation for Exchange online mailbox, I think it may not be suitable for migrated mailboxes.


    If the response is helpful, please click "Accept Answer" and upvote it.