0

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

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Ritesh734
  • 5
  • 2

1 Answers1

0

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.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Thanks you for your response, I was looking into Immutable identifiers when a come across this [https://stackoverflow.com/questions/71859435/can-i-set-identifiers-immutable-in-office-js-by-adding-prefer-idtype-immutabl] saying Immutable IDs do not work with any office.js apis. Do you know if it is possible and how to go about doing this ? – Ritesh734 Mar 01 '23 at 13:26
  • Consider adding a custom property to the item with your own ID, see the [Office.CustomProperties interface](https://learn.microsoft.com/en-us/javascript/api/outlook/office.customproperties?view=outlook-js-preview) for more information. – Eugene Astafiev Mar 01 '23 at 14:12
  • Hi thanks, I was just looking into this I think custom property are the way to do this as a work around. – Ritesh734 Mar 01 '23 at 16:35
  • This is a possible solution, not a workaround ;) – Eugene Astafiev Mar 01 '23 at 19:34