[英]How to change email subject in C# using Exchange Web Services
我有一段代碼可以通過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類是解決之道,但我不清楚如何告訴我要將電子郵件主題更改為subject參數。
有任何想法嗎? 使用UpdateItemType甚至是執行此操作的最佳方法嗎?
您應該使用EWS托管API代替EWS,因為它使用起來更簡單:
EWS托管API-下載: http : //www.microsoft.com/download/en/details.aspx?id=13480
EWS托管API-SDK: http : //msdn.microsoft.com/zh-cn/library/dd633710 (v = exchg.80).aspx
除此之外,您不使用ItemChangeType和UpdaetItemType來修改項目。 使用Item.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? 那兩個是不同的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.