gautamsi / ews-javascript-api

EWS API for TypeScript/JavaScript - ported from OfficeDev/ews-managed-api - node, cordova, meteor, Ionic, Electron, Outlook Add-Ins
MIT License
281 stars 72 forks source link

email.Move from inbox to public folder gives error #438

Open pascalgross opened 3 months ago

pascalgross commented 3 months ago

When trying to move a mail item from an user's inbox to a public folder, I get the following API error:

'Access to this API requires the following permissions: 'MailExport-Internal.Read.All,MailExport-Internal.Read.Shared,MailExport-Internal.ReadWrite.All,MailExport-Internal.ReadWrite.Shared'. However, the application only has the following permissions granted: 'full_access_as_app,Mail.ReadWrite,Mail.Read,Mail.Send'.";error_category="invalid_grant"

I'm unable to grant those internal permissions but the app has "full_access_as_app" but it doesn't seem to be sufficient.

My codes looks like this:

let token = this._token;
if (!token) {
  token = await this.getToken();
}

const ews = new ExchangeService();
ews.Url = new Uri('https://outlook.office365.com/EWS/Exchange.asmx');
ews.Credentials = new OAuthCredentials(token);
ews.ImpersonatedUserId = new ImpersonatedUserId(
  ConnectingIdType.PrincipalName,
  principalName
);

const email = await EmailMessage.Bind(ews, new ItemId(mailItemId));
await email.Move(new FolderId(folderId));
gautamsi commented 3 months ago

you would need to assign some permissions to Azure app which may not be available anymore, switch to RBAC permission and try to assign permission in the Exchange Server app permission.