我有一段代码,通过 Exchange Web 服务进行连接,并且有消息 ID。我需要将此电子邮件的主题更改为传递到我的方法中的字符串,以便稍后在我的工作流程中成功处理。但是,我对如何使用交换 Web 服务类有点困惑,我的代码如下:
public bool SetEmailCorrectSubject(string msgID, string subject)
{
bool bSuccess = true;
if (String.IsNullOrEmpty(msgID))
{
return false;
}
try
{
ItemIdType messageId = new ItemIdType();
messageId.Id = msgID;
ItemChangeDescriptionType desc = new ItemChangeDescriptionType();
// Not sure how to set this up
ItemChangeType itemChange = new ItemChangeType();
itemChange.Item = messageId;
UpdateItemType updateItem = new UpdateItemType();
}
catch (Exception e)
{
_logger.Error("error with resending email with title", e);
return false;
}
return bSuccess;
}
据我了解,UpdateItemType 类是可行的方法,但我不清楚如何告诉它我想要将电子邮件主题更改为主题参数。
有什么想法吗?使用 UpdateItemType 是执行此操作的最佳方法吗?
最佳答案
您应该使用 EWS 托管 API,而不是 EWS,因为它使用起来更简单:
EWS 托管 API - 下载:http://www.microsoft.com/download/en/details.aspx?id=13480
EWS 托管 API - SDK:http://msdn.microsoft.com/en-us/library/dd633710(v=exchg.80).aspx
除此之外,您不使用 ItemChangeType 和 UpdaetItemType 来修改项目。使用 Item.Bind() 方法绑定(bind)到项目,更改主题并更新它:
var service = new ExchangeService(ExchangeVersion.Exchange2010_SP1)
{
UseDefaultCredentials = true,
Url = new Uri("https://casserver/ews/exchange.asmx")
};
Item item = Item.Bind(service, new Itemid(msgid));
item.Subject = "test";
item.Update(ConflictResolutionMode.AutoResolve);
顺便说一句,您确定有 ItemId 吗?或者您有 RFC 822 消息 ID 吗?这两者是不同的。
关于c# - 如何使用 Exchange Web 服务在 C# 中更改电子邮件主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8015587/