Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EWS Managed API : Reply to a message while adding an internet header

I am building a small client that can automatically reply to some emails. I would like to add a custom internet header to these replies.

What I tried to do is to set the extended property to the email I receive, and use the EmailMessage.Reply method.

But it does not work. I also tried to use the EmailMessage.CreateReply. However, it creates a ResponseMessage object that has no SetExtendedProperty method.

This the relevant part of the 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);
like image 244
afewcc Avatar asked Jul 30 '13 03:07

afewcc


1 Answers

You first need to save the ResponseMessage in the Drafts folder via the Save() method and then you can obtain an instance of the EmailMessage. This is the same pattern 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();
like image 77
SliverNinja - MSFT Avatar answered Oct 13 '22 23:10

SliverNinja - MSFT