Outlook VSTO C# get sending email sensivity label

Emre 21 Reputation points
2022-10-25T08:04:48.103+00:00

Hello friends,

I need to get sending email sensivity level on Application_ItemSend event. We choose internal, public or confidential sensivity levels while sending email in our company however most of the people choose wrong level or they forgot to choose any level while sending external domains. So i am preparing a VSTO add-in now i catch send email event but i couldn't manage to get sensivity label value.

Thanks in advance.

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,532 questions
0 comments No comments
{count} votes

Accepted answer
  1. Eugene Astafiev 891 Reputation points
    2022-10-25T17:07:46.743+00:00

    The Outlook object model doesn't provide any ready-made properties for that. Sensitivity labels are stored in custom properties that can be accessed by using the PropertyAccessor object. For example, to read the property you can use the following code:

       var mipLabels = currentMailItem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/msip_labels/0x0000001F") as string;  
    

    To set a property you can use the following code:

       public void SetMIP_LabelPublic(MailItem newMailItem)  
        {  
               var lblID        = "00012345-0000-0000-C000-0000000000XX";    // your label ID  
               var tenantId     = "00012345-0000-0000-C000-0000000XXXXX";    // your azure information tenant (your company) id  
               var mipMethod    = "Privileged";              
               var dd           = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.CreateSpecificCulture("en-us"));  
         
               var mipPropertyText = $"MSIP_Label_{lblID}_Enabled=true; "  
                   + $"MSIP_Label_{lblID}_SetDate={dd}; "  
                   + $"MSIP_Label_{lblID}_Method={mipMethod}; "                  
                   + $"MSIP_Label_{lblID}_SiteId={tenantId}; ";  
         
         
               newMailItem.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/msip_labels/0x0000001F", mipPropertyText);  
       }  
    

    You can try using MFCMAPI or OutlookSpy for exploring internals of Outlook and custom property values.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful