繁体   English   中英

如何使用Exchange Web Services在C#中更改电子邮件主题

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM