outlookoffice-addinsoutlook-web-addinsgetmessage

How can I get the message above that I am replying to in outlook addin using office js?


In Outlook add-ins on the compose side, how can I retrieve the main message ID when composing a reply or forward? I need to access the unique ID of the original email I'm replying to or forwarding within the Office JavaScript API for Outlook.

I've explored using the getEntities().messageId.getAsync method, but I'm uncertain about the exact implementation to retrieve the main message ID. Could someone provide guidance or an example snippet that demonstrates how to asynchronously fetch the main message ID within the compose side of an Outlook add-in using the Office JavaScript API? enter image description here


Solution

  • A compose item may or may not exist when an add-in is launched. Below code first saves the item, thus creating it if not created and then returns the itemId.

    Office.context.mailbox.item.saveAsync(function(result) {
      var itemId = result.value;
      console.log("Item ID: " + itemId);
    });
    

    It is not possible to retrieve the itemId of the parent item you are replying to. But you can get the conversationId, and then fetch that conversation via graph/REST.