c# – EWS托管API:添加互联网标头时回复邮件
作者:互联网
我正在构建一个可以自动回复某些电子邮件的小客户端.我想为这些回复添加自定义互联网标题.
我尝试做的是将扩展属性设置为我收到的电子邮件,并使用EmailMessage.Reply方法.
但它不起作用.我还尝试使用EmailMessage.CreateReply.但是,它会创建一个没有SetExtendedProperty方法的ResponseMessage对象.
这是代码的相关部分:
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);
解决方法:
首先需要将ResponseMessage
保存在草稿文件夹via the Save()
method中,然后才能获得EmailMessage
的实例.这是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();
标签:c,net,ews-managed-api,exchange-server-2010 来源: https://codeday.me/bug/20190520/1141925.html