![](/img/trans.png)
[英]Allow impersonation users to login to Exchange Server by EWS Managed API 2.0
[英]Exchange EWS Managed API 2.0 get by date
我使用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;
我想改善这一行if (item.DateTimeCreated < DateTime.Now.AddDays(-3)) continue;
因为当我使用它时,api从收件箱中获取所有消息,并且如果它的年龄超过三天,则继续。 我想在代码的前面指定此过滤器,因此api不必处理所有消息。
如果我正确理解了该问题,则应该可以正常工作。 您可以在此处查看所有可用的搜索过滤器: EWS搜索过滤器
ItemView view = new ItemView(int.MaxValue);
FindItemsResults<Item> findResults;
view.PropertySet = itempropertyset;
SearchFilter searchFilter =
new SearchFilter.IsGreaterThan(ItemSchema.DateTimeReceived, DateTime.Now.AddDays(-3));
findResults = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.