Share via

Office.js Concern about select multiple email

Dự Nguyễn Trọng 0 Reputation points
2026-06-12T03:11:09.2866667+00:00

Hi I'm trying to build an add-in for Outlook. Mine only support to process 1 email at a time. I'm using getSelectedItemsAsync to get selected email.

When trying to determine multiple selection to show a clear error message, relied on result of getSelectedItemsAsync, my expect should be
2 normal -> warning page shown.

1 normal + 1 encrypted -> warning page shown.

2 encrypted -> warning page shown.

1 encrypted -> continues normally.
But the real thing is in case multiple select, result never show me encrypted item. Is there anyway for me to know that multiple item are selected and still have shown encrypted item?
If there is limitation, please help share the related documentation

Microsoft 365 and Office | Development | Office JavaScript API
0 comments No comments

1 answer

Sort by: Most helpful
  1. Michelle-N 18,185 Reputation points Microsoft External Staff Moderator
    2026-06-12T04:08:16.8333333+00:00

    Hi @Dự Nguyễn Trọng

    Based on your post, I understand that you are developing an Outlook add-in that only supports processing one email at a time. You are using the getSelectedItemsAsync API to check the user's selection. Your goal is to display a clear warning page whenever multiple items are highlighted, including mixed selections containing encrypted emails. However, you've discovered that when multiple items are selected, Outlook quietly excludes encrypted items from the returned array entirely, preventing you from receiving a clear count or triggering your warning page in those specific scenarios.

    After researching the behavior of the getSelectedItemsAsync API and Outlook's handling of protected items, here is what is happening under the hood:

    The Office JavaScript API enforces strict security boundaries around encrypted messages, such as those protected by S/MIME, IRM (Information Rights Management), or Microsoft Purview Message Encryption. Because an add-in cannot inherently read the encrypted payload or guarantee the security of the metadata in a bulk context, Outlook applies a strict client-side security guardrail. While the Item Multi-Select Documentation specifies which properties are typically returned for a multi-selection array, it intentionally drops encrypted objects from that array rather than throwing a hard error or passing an unreadable object placeholder. Currently, there is no official documentation confirming direct support for gathering metadata on multiple encrypted items simultaneously using this API.

    Even though the API hides the encrypted items within the multi-select array, you can use the built-in properties of the Outlook UI object model to deduce what the user is doing. Since your core goal is simply to show a warning page whenever more than 1 item is actually highlighted by the user, you can cross-reference the array against the active reading pane item.

    When an add-in task pane is open, Office.context.mailbox.item always points to the primarily active email (the one currently rendering in the reading pane). You can implement the following deduction logic:

      if (result.status === Office.AsyncResultStatus.Succeeded) {
        const items = result.value;
        if (items.length === 0) {
          // Could be: nothing selected, OR multiple encrypted items selected
          showWarning("No readable items selected. If you selected multiple emails, some may be encrypted or protected.");
          return;
        }
        if (items.length > 1) {
          // Definitely multiple normal emails — your add-in only supports 1
          showWarning("Please select only one email at a time.");
          return;
        }
        // items.length === 1
        // Could still be 1 normal + 1+ encrypted selected silently
        // You cannot distinguish this case from a true single selection
        processSingleItem(items[0]);
      }
    });
    
    

    I hope this information helps.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.