使用EWS跟踪日志消息ID或InternalMessageID从Exchange获取电子邮件

时间:2017-11-16 11:12:10

标签: exchangewebservices exchange-server-2010

我正在开发一个跟踪我们公司交换电子邮件的应用程序。 我们能够从跟踪日志中获取信息,但在log -by设计中 - 没有主题或正文消息。 因此,我们的下一步是使用EWS在需要时获取消息详细信息。 问题是在跟踪日志中我们找到ID:

MessageId ,格式为" F533E7F015A2E24F8D8ABFE2587117C601EDF245@blstex02.subdomain.domain.com"

格式" 5840818"

InternalMessageId

如果在EWS中我们使用此ID通过ID查找消息,我们总是得到" Id格式错误。"例外。 这是我们使用的代码:

public static EmailMessage GetEmailById(string uNameToImpersonate, string StringItemId)
        {
            return EmailMessage.Bind(GetService(uNameToImpersonate), new ItemId(StringItemId));
        }

我是EWS的新手,所以也许我错过了一些非常简单的事情...... 谢谢你的帮助

1 个答案:

答案 0 :(得分:0)

您只能使用EWSI绑定到消息,请参阅https://msdn.microsoft.com/en-us/library/office/dn605828(v=exchg.150).aspx以获取更详细的讨论。对于InternetId,您需要使用findItem操作搜索具有该特定Id的消息,例如

  ItemView ivew = new ItemView(1);
  service.TraceEnabled = true;
  ExtendedPropertyDefinition PidTagInternetMessageId = new ExtendedPropertyDefinition(4149, MapiPropertyType.String);
  SearchFilter sf = new SearchFilter.IsEqualTo(PidTagInternetMessageId, "F533E7F015A2E24F8D8ABFE2587117C601EDF245@blstex02.subdomain.domain.com");
  FindItemsResults<Item> iCol = service.FindItems(WellKnownFolderName.Inbox, sf, ivew);

  foreach (Item item in iCol.Items)
  {
    Console.WriteLine(item.Subject);
  }