How to fetch email internet headers in an Outlook on-send add-in?

MikeS 1 Reputation point
2022-10-21T17:26:44.583+00:00

Hi All,

We have a client that requires that an action take place when sending emails with certain Microsoft Information Protection/Azure Information Protection (MSIP/AIP) labels. We have a desktop Outlook add-in that does this perfectly.

Now however the client is requesting this same add-in but using the new modern style Outlook add-ins. We have created an on-send add-in to accomplish this, but we cannot get access to any internet headers in an Office.ComposeMessage. In fact, we cannot get any headers to be returned.

Here is our code:

async function fetchInternetHeaders(mailItem: Office.MessageCompose,   
                                    tags: string[]): Promise<string[]> {  
  return new Promise(function(resolve, reject) {  
    try {  
      let myTags: string[] = [  
        "msip_labels",  // This is the value we need  
        "x-ms-has-attach", // This is for testing  
        "PR_SUBJECT_W", // This is for testing  
        "http://schemas.microsoft.com/mapi/proptag/0x0037001F", // test  
        "http://schemas.microsoft.com/mapi/proptag/0x5D07001F", // test  
        "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/msip_labels/0x0000001F", // Another way to get msip_labels  
      ];  
      mailItem.internetHeaders.getAsync(myTags, function(asyncResult) {  
        if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {  
          debug.Log("onSend.fetchInternetHeaders", "Selected headers: " + JSON.stringify(asyncResult.value));  
        } else {  
          debug.Log(  
            "onSend.fetchInternetHeaders",  
            "Error getting selected headers: " + JSON.stringify(asyncResult.error)  
          );  
        }  
        resolve(["FetchedInternetHeaders"]);  
      });  
    } catch (error) {  
      debug.Log("onSend.fetchInternetHeaders", "Error occurred", error);  
      reject(error);  
    }  
  });  

Note: We ignored the parameter "tags" to make everything as simple as possible.

The call succeeds but the returned array is always empty, even for simple properties like the email Subject. What are we doing wrong?

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
981 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,910 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Eugene Astafiev 891 Reputation points
    2022-10-23T10:19:49.213+00:00

    Both COM add-ins and Web add-ins don't provide any internet headers until the message is sent out. You may expect the internet headers set when the message is put to the Sent Items folder, but before that they are not created and stamped by the service/transport provider.

    Most probably you need to access user properties, see the UserProperties object in the Outlook object model. But the Office JavaScript API (OfficeJS) doesn't provide anything for that out of the box, you need to use EWS or Graph API to access such properties from web add-ins.

    You can specify data specific to an item in the user's mailbox using the CustomProperties object. For example, your mail add-in could categorize certain messages and note the category using a custom property messageCategory. Or, if your mail add-in creates appointments from meeting suggestions in a message, you can use a custom property to track each of these appointments. This ensures that if the user opens the message again, your mail add-in doesn't offer to create the appointment a second time.

    Be aware, changes to custom properties are stored on in-memory copies of the properties for the current Outlook session. To make sure these custom properties will be available in the next session, use CustomProperties.saveAsync.

    These add-in-specific, item-specific custom properties can only be accessed by using the CustomProperties object. Like I wrote earlier, these properties are different from the custom, MAPI-based UserProperties in the Outlook object model, and extended properties in Exchange Web Services (EWS). You cannot directly access CustomProperties by using the Outlook object model, EWS, or REST. To learn how to access CustomProperties using EWS or REST, see the section Get custom properties using EWS or REST.

    You can post or vote for an existing feature request on Tech Community where they are considered when the Office dev team go through the planning process. Use the github label: Type: product feature request at https://aka.ms/M365dev-suggestions .

    0 comments No comments

Your answer

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