Search code examples
outlookoffice-jsoutlook-addinoffice-addinsoutlook-web-addins

Outlook Add-in how do i access the itemId of an email when using ItemSend


I am creating my first Outlook Add-in and i need to be able to get the itemID of an email when it is sent.

I have setup a ExtensionPoint in the manifest which is being triggered when an email is sent. The function being called is saving the email in order to get the itemID. However the itemID that is returned by saveAsync is different from the itemId of the sent email in the sent folder.

Doing some research I found out that saveAsync is only returning a temporary itemID which is changed when the email is sent and move to the Sent folder.

So the question is how do I get the itemId of the sent email ? is there a better way of doing this or am I missing something ?

<ExtensionPoint xsi:type="Events">
<Event Type="ItemSend" FunctionExecution="synchronous" FunctionName="onEmailOrEventSend" />
</ExtensionPoint>
function onEmailOrEventSend(event) {
    mailboxItem.saveAsync({ asyncContext: event },(results) => {
        if (results.error) {
            console.error("Failed");
        } else {
           console.log("Saved!!!! " + results.value);
            results.asyncContext.completed({ allowEvent: true });
        }
    });

I have tried to get the itemId before the email is saved but that does not work


Solution

  • The itemId, like the EntryID in COM add-ins, is not a static value. The ID will change whenever an item is moved around in Exchange. The saveAsync call results in the email being saved to the Drafts folder. When it is sent the item first moved to the Outbox and then into the Sent Items folder. Each of those folder changes (Drafts, Outbox, and Sent Items) results in a change to the itemId field. The EWS documentation states the following:

    Identifiers in Exchange are opaque. For example, the EwsId is created from several pieces of information that are not important to you as the developer, but are important to Exchange.

    In Graph API Immutable identifiers (IDs) may enable your application to obtain an ID that does not change for the lifetime of the item. See Obtain immutable identifiers for Outlook resources for more information.