使用EWS托管API林到我的C#项目和我们的Exchange 2010服务器之间的通信。 我用这个代码来获得在收件箱中的所有邮件从现在起,三天回来。
var ews = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
ews.Credentials = new NetworkCredential(usr, psw, dmn);
ews.AutodiscoverUrl(url);
PropertySet itempropertyset = new PropertySet(BasePropertySet.FirstClassProperties);
itempropertyset.RequestedBodyType = BodyType.Text;
ItemView view = new ItemView(int.MaxValue);
FindItemsResults<Item> findResults;
view.PropertySet = itempropertyset;
do
{
findResults = ews.FindItems(WellKnownFolderName.Inbox, view);
foreach (Item item in findResults.Items)
{
if (item.DateTimeCreated < DateTime.Now.AddDays(-3)) continue;
item.Load(itempropertyset);
var message = EmailMessage.Bind(ews, item.Id,
new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.Attachments));
string to = message.ToRecipients[0].Address.ToLower();
string body = item.Body;
}
view.Offset += findResults.TotalCount;
} while (findResults.MoreAvailable);
现在的问题。 我想提高此线if (item.DateTimeCreated < DateTime.Now.AddDays(-3)) continue;
因为当我用这个,这个API得到所有从收件箱中的消息,只是继续如果旧的然后三天。 我想在前面的代码指定此过滤器,因此API不必须处理所有消息。