1

我的测试代码适用于使用 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 包交换网络服务,这就是我的代码可以识别出Exchange2013

4

1 回答 1

2

这对我有用:

item.Delete(DeleteMode.MoveToDeletedItems);

项目是电子邮件

于 2018-11-22T15:28:40.603 回答