【发布时间】:2019-11-25 19:13:32
【问题描述】:
使用 VB,我希望能够从特定的邮件子文件夹开始按日期和主题搜索电子邮件并返回所有邮件项目,这就是我到目前为止所收集的内容
由于某些项目在 Outlook365 中位于“其他”中,因此也需要能够搜索它们
Dim searchFilterCollection As List(Of SearchFilter) = New List(Of SearchFilter)()
Dim searchdate As DateTime = New DateTime(2019, 11, 19) 'Year, month, day
Dim greaterthanfilter As SearchFilter = New SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeReceived, searchdate)
Dim lessthanfilter As SearchFilter = New SearchFilter.IsLessThan(ItemSchema.DateTimeReceived, searchdate.AddDays(1))
searchFilterCollection.Add(New SearchFilter.SearchFilterCollection(LogicalOperator.And, greaterthanfilter, lessthanfilter))
searchFilterCollection.Add(New SearchFilter.IsEqualTo(FolderSchema.DisplayName, "My Folder"))
searchFilterCollection.Add(New SearchFilter.ContainsSubstring(ItemSchema.Subject, "Test Subject"))
' Create the search filter.
Dim searchFilter As SearchFilter = New SearchFilter.SearchFilterCollection(LogicalOperator.And, searchFilterCollection.ToArray())
' Create a view with a page size of 50.
Dim view As New ItemView(50)
'Identify the Subject and DateTimeReceived properties to return.
'Indicate that the base property will be the item identifier
view.PropertySet = (New PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, ItemSchema.DateTimeReceived))
' Order the search results by the DateTimeReceived in descending order.
view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending)
' Set the traversal to shallow. (Shallow is the default option; other options are Associated and SoftDeleted.)
view.Traversal = ItemTraversal.Shallow
' Send the request to search the Inbox and get the results.
Dim findResults As FindItemsResults(Of Item) = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view)
For Each item As Item In findResults
Dim message As EmailMessage = EmailMessage.Bind(exchange, item.Id)
Dim listitem As ListViewItem = New ListViewItem({message.DateTimeReceived.ToString(), message.From.Name.ToString() & "(" + message.From.Address.ToString() & ")", message.Subject, (If((message.HasAttachments), "Yes", "No")), message.Id.ToString()})
lstMsg.Items.Add(listitem)
Next
If findResults.Items.Count <= 0 Then
lstMsg.Items.Add("No Messages found!!")
End If
【问题讨论】:
-
好的——这就是你到目前为止所做的。有问题吗?它有效吗?如果不起作用,错误或意外输出在哪里?
-
不,如果我移除 2 个过滤器 searchFilterCollection.Add(New SearchFilter.IsEqualTo(FolderSchema.DisplayName, "My Folder")) searchFilterCollection.Add(New SearchFilter.ContainsSubstring(ItemSchema.主题,“测试主题”))然后它从主收件箱中带回当天的电子邮件,我想以某种方式获取它,以便我可以在收件箱及其子文件夹中搜索给定主题的文件夹,但我无法得到它从指定的子文件夹开始
-
我找到了一个不理想但确实有效的解决方法,在此行之前 Dim findResults As FindItemsResults(Of Item) = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view),我有一个函数调用为我获取文件夹名称的文件夹详细信息,在这一行中用作 myfolder.id 而不是 wellknown 文件夹,但您必须获取每个文件夹的 id,我想要的是设置 staruing 文件夹以搜索到某事和然后只搜索该文件夹和所有子文件夹。
-
我有一个问题,一些电子邮件登陆“其他”邮箱并且没有集中,我如何在那个邮箱中搜索,我尝试搜索其他文件夹并尝试了我找到的其他代码它找到了“Allitems”文件夹,但它仍然没有显示任何位于“Other”中的电子邮件
-
您可以通过此链接将该信息添加到问题中:stackoverflow.com/posts/58940977/edit - 这将改善您的问题并提高您获得答案的机会。
标签: vb.net exchangewebservices