Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ews java api - How to set permission/classification (public/restricted/internal) to Email message

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("[email protected]");
// 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://docs.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

like image 612
StackOverFlow Avatar asked Jul 24 '18 14:07

StackOverFlow


1 Answers

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("[email protected]");
                msg.getToRecipients().add("[email protected]");


            // 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

like image 125
StackOverFlow Avatar answered Oct 27 '22 22:10

StackOverFlow