从 EWS ExchangeVersion.Exchange2013 与 2010 中删除电子邮件
Delete emails from EWS ExchangeVersion.Exchange2013 vs 2010
我的测试代码使用 ExchangeVersion.Exchange2010 删除电子邮件,如下所示。
var finalsearchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.And)
{
new SearchFilter.IsGreaterThan(EmailMessageSchema.DateTimeReceived, DateTime.Now.AddDays(-15)),
};
view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);
view.Traversal = ItemTraversal.Shallow;
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.Credentials = new WebCredentials("user@example.com", "password", "domain");
service.AutodiscoverUrl("user@example.com");
FindItemsResults<Item> items = service.FindItems(new FolderId(WellKnownFolderName.Inbox, new Mailbox("mailboxName@example.com")), finalsearchFilter, view);
if (items.Count() != 0)
{
IEnumerable<ItemId> itemIds = from p in items.Items select p.Id;
service.DeleteItems(itemIds, DeleteMode.SoftDelete, null, null);
}
但是如果我将 2010 更改为 2013,我会立即收到一条错误消息。
Microsoft.Exchange.WebServices.Data.ServiceVersionException : Exchange Server doesn't support the requested version.
有人可以指出我所缺少的正确方向吗?当我查看 msdn 教程时,他们在调用 exchangeservice 对象时仍然使用 2010,有时使用 2007 参考。我还看到其他帖子说我需要专门把 ExchangeVersion.Exchange2010
放在里面,但我已经有了。如果有帮助,我还下载了最新的 nuget 包交换 web 服务,这就是我的代码如何识别 Exchange2013
这对我有用:
item.Delete(DeleteMode.MoveToDeletedItems);
项目是电子邮件
我的测试代码使用 ExchangeVersion.Exchange2010 删除电子邮件,如下所示。
var finalsearchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.And)
{
new SearchFilter.IsGreaterThan(EmailMessageSchema.DateTimeReceived, DateTime.Now.AddDays(-15)),
};
view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);
view.Traversal = ItemTraversal.Shallow;
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.Credentials = new WebCredentials("user@example.com", "password", "domain");
service.AutodiscoverUrl("user@example.com");
FindItemsResults<Item> items = service.FindItems(new FolderId(WellKnownFolderName.Inbox, new Mailbox("mailboxName@example.com")), finalsearchFilter, view);
if (items.Count() != 0)
{
IEnumerable<ItemId> itemIds = from p in items.Items select p.Id;
service.DeleteItems(itemIds, DeleteMode.SoftDelete, null, null);
}
但是如果我将 2010 更改为 2013,我会立即收到一条错误消息。
Microsoft.Exchange.WebServices.Data.ServiceVersionException : Exchange Server doesn't support the requested version.
有人可以指出我所缺少的正确方向吗?当我查看 msdn 教程时,他们在调用 exchangeservice 对象时仍然使用 2010,有时使用 2007 参考。我还看到其他帖子说我需要专门把 ExchangeVersion.Exchange2010
放在里面,但我已经有了。如果有帮助,我还下载了最新的 nuget 包交换 web 服务,这就是我的代码如何识别 Exchange2013
这对我有用:
item.Delete(DeleteMode.MoveToDeletedItems);
项目是电子邮件