8

I am drafting email in custom folder.

EmailMessage msg= new EmailMessage(service);
msg.setSubject("Hello world!");
msg.setBody(MessageBody.getMessageBodyFromText("Draft email using the EWS Java API."));
msg.getToRecipients().add("someone@contoso.com");
// Tried to set extended property but not worked
ExtendedPropertyDefinition headerProperty = new ExtendedPropertyDefinition(
                    DefaultExtendedPropertySet.InternetHeaders,
                    "X-Classification",
                    MapiPropertyType.String);
            msg.setExtendedProperty(headerProperty,"Provision X-header Internet message header");
msg.save(CUSTOM_FOLDER_ID);

I came to know that extended property will be helpful for classification/permission header. Ref link - https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-provision-x-headers-by-using-ews-in-exchange But how to set classification/permission ? X-Classification-Restricted something like this or any other way ?

I dont want to use setImportance / setSensitivity methods.

Manually we are setting in following way enter image description here

Expectation from ews api to set classification/permission from code enter image description here

How to set permission/classification(public/Restricted/Internal) to EmailMessage using ews java api?

Code snippet of working example appreciated. Thanks in advance

StackOverFlow
  • 4,486
  • 12
  • 52
  • 87
  • Are you looking for the item property [sensivity](https://learn.microsoft.com/en-us/dotnet/api/microsoft.exchange.webservices.data.item.sensitivity?view=exchange-ews-api#Microsoft_Exchange_WebServices_Data_Item_Sensitivity)? – LuCio Jul 24 '18 at 14:51
  • @LuCio No- I dont want sensitivity property. I am looking for permission/Classification for EmailMessage. – StackOverFlow Jul 24 '18 at 15:23
  • @LuCio No, sensitivity not required – StackOverFlow Jul 25 '18 at 07:07

1 Answers1

3

x-iccategory InternetHeaders is required to set classification/permission to email.

x-iccategory with value from [1-4] & supply value as string

Following are Values with classification/permission type of x-iccategory

1=Highly, 2=Restricted, 3=Internal, 4=Public

Following in sample code snippet

   EmailMessage msg = new EmailMessage(exchangeService);
                msg.setSubject("Ews api code....");        
                msg.setBody(MessageBody.getMessageBodyFromText("** Email with classification using EWS Java API."));
                msg.setFrom(new EmailAddress("some1@test.com");
                msg.getToRecipients().add("some2@test.com");


            // Define the extended property
            ExtendedPropertyDefinition extPropDef = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.InternetHeaders, "x-iccategory", MapiPropertyType.String);

            // Stamp the extended property with value on a message. 2- Restricted
            msg.setExtendedProperty(extendedPropertyDefinition, "2");

            msg.send();

Classification/permission not applicable to email message from draft/custom folder

Note - Classification/Permission comes in picture when you trigger that email. Email goes to transport pipeline 1st and based on the value(Restricted/Public...) it gets applied

StackOverFlow
  • 4,486
  • 12
  • 52
  • 87