How to get the Item ID of a mail item in Exchange 2010

為{幸葍}努か 提交于 2019-12-04 20:25:54

Item.Bind returns an Item, not an ItemId, so you get a compile-time error. You already have the ItemId. It's right there on the EmailMessage you're getting with each iteration unless you're referring to other ids in Exchange, such as the EntryId.

ItemId itemID = email.Id;

This is unnecessary if you want to update the items in that block of code or thereabouts, though. For that, you just need to make the changes (mark them as read), then place them into a List or other IEnumerable and use ExchangeService.UpdateItems to update the EmailMessages.

If you want to store the ItemIds for later use, you should know that the ItemId is NOT a permanent, unchanging property. It will change if the Item in question is moved to another mailbox or moved to another folder. There may be other cases that can change it, such as service pack installations/version upgrades or even the passage of enough time, although I cannot confirm those myself.

EDIT: To answer the below statement, it seems that ContainsSubstring doesn't work too well on email addresses. You can do this with a queryString:

String queryString = "from:domain.co.uk AND isread:false AND hasattachment:true";

Give that a try. My syntax could be a hair off depending on how you want to do it. Exchange Guru Glen Scales has a nice blog post that has several links to the somewhat scattered MS documentation on AQS:

http://gsexdev.blogspot.com/2010/08/using-exchange-search-and-aqs-with-ews.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!