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

MikeS 1 Reputation point

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  
        "", // test  
        "", // test  
        "{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 {  
            "Error getting selected headers: " + JSON.stringify(asyncResult.error)  
    } catch (error) {  
      debug.Log("onSend.fetchInternetHeaders", "Error occurred", 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.
757 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,062 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Eugene Astafiev 891 Reputation points

    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 .

    0 comments No comments