To set an Azure Information Protection label for sending email through EWS code, you can use the following steps:
- Create a new email message using the
Microsoft.Exchange.WebServices.Data.EmailMessage
class. - Set the
Microsoft.Exchange.WebServices.Data.EmailMessage.Sensitivity
property toMicrosoft.Exchange.WebServices.Data.Sensitivity.Normal
. - Set the
Microsoft.Exchange.WebServices.Data.EmailMessage.Headers
property to include theMSIP_Label_<GUID>_Enabled
header, where<GUID>
is the GUID of the label you want to apply. - Send the email message using the
Microsoft.Exchange.WebServices.Data.EmailMessage.SendAndSaveCopy()
method.
Here is an example code snippet that demonstrates how to set an Azure Information Protection label for sending email through EWS code in C#:
EmailMessage message = new EmailMessage(service);
message.Subject = "Test Email";
message.Body = new MessageBody("This is a test email.");
message.ToRecipients.Add("recipient@example.com");
message.Sensitivity = Sensitivity.Normal;
message.Headers.Add("MSIP_Label_12345678-1234-5678-1234-567812345678_Enabled", "true");
message.SendAndSaveCopy();
Please note that you will need to replace 12345678-1234-5678-1234-567812345678
with the GUID of the label you want to apply.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.