EWS Managed API: reply to a message when adding an Internet header

I am creating a small client that can automatically reply to some emails. I would like to add a special internet header to these answers.

What I tried to do was set the extended property to the received email and use the EmailMessage.Reply method.

But that will not work. I also tried using EmailMessage.CreateReply . However, it creates a ResponseMessage object that does not have a SetExtendedProperty method.

This is the corresponding piece of code:

 private static readonly ExtendedPropertyDefinition _redFlag = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.InternetHeaders, "X-RED", MapiPropertyType.String); private static readonly PropertySet _customHeaders = new PropertySet(BasePropertySet.FirstClassProperties, _redFlag); /* ... some code to connect to Exchange Service ... */ EmailMessage email = EmailMessage.Bind(_service, id, _customHeaders); email.SetExtendedProperty(_redFlag, "test"); email.Reply(new MessageBody(answer), false); 
+4
source share
1 answer

First you need to save ResponseMessage in the Drafts folder using the Save() method , and then you can get an instance of EmailMessage . This is the same template used to add attachments to message replies .

 var message = (EmailMessage) Item.Bind(service, new ItemId(uniqueId), PropertySet.FirstClassProperties); var reply = message.CreateReply(false); reply.BodyPrefix = "Response text goes here"; var replyMessage = reply.Save(WellKnownFolderName.Drafts); // default is drafts folder - this is explicit replyMessage.SetExtendedProperty(_redFlag, "test"); replyMessage.Update(ConflictResolutionMode.AlwaysOverwrite); replyMessage.SendAndSaveCopy(); 
+4
source

Source: https://habr.com/ru/post/1494182/


All Articles