Search code examples
exchangewebservicesoutlook-addinoffice-addins

Deleting an Outlook Message via the EWS API?


I'm developing an Outlook add-in and trying to delete a message in a via the EWS API (soap envelopes). Following the docs DeleteItem Operation unfortunately does not work for me. I'm making an mailbox.makeEwsRequestAsync() request with the follwing request envelope. All my other EWS Request are working just fine, only this request always fails with an ErrorInvalidRequest response. I've googled and searched stackoverflow already quite a lot with no success. Unfortunately I have to use EWS to do this. Also a soft delete (moving to trash) works.

Request:

request = '<?xml version="1.0" encoding="utf-8"?> ' +
        '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ' +
        '        xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types"> ' +
        '   <soap:Body> ' +
        '       <DeleteItem DeleteType="HardDelete" xmlns="https://schemas.microsoft.com/exchange/services/2006/messages">' +
        '           <ItemIds> ' +
        '               <t:ItemId Id="' + item_id + '/> ' +
        '           </ItemIds> ' +
        '       </DeleteItem> ' +
        '   </soap:Body> ' +
        '</soap:Envelope>';

Response: enter image description here

Any help would be greatly appreciated!

Solution (Edit): The answer from Glen Scales below works perfectly. Just moving the Item to a purges folder, in my case the 'recoverableitemspurges' folder, which is not visible for the user and hence equal to a hard delete For reference, all the deletedItem folders: https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/deleting-items-by-using-ews-in-exchange#find-out-more-about-deleting-items


Solution

  • makeEWSRequestAsync can only be used on a subset of EWS operations these are listed in https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/understanding-outlook-add-in-permissions (under ReadWriteMailbox permission). DeleteItems is not allowed, moveitems is so you could try just moving the Message to the Purges folders which would be equal to a Hard Delete.