大家。 我正在使用Microsoft Outlook 15.0对象库来处理邮箱。
当我通过我的代码搜索有时它不会返回任何结果,同样的查询通过Outlook显示消息:
或
请告诉我,如何以编程方式获得所有结果。直接从服务器获取它们会很好。
现在我使用以下代码:
public BindingList<Mail> SearchForEmails(string query, out int resultsCount, List<string> excludedCategories)
{
resultsCount = 0;
BindingList<Mail> searchResults = new BindingList<Mail>();
// Check if Instant Search is enabled and operational in the default store.
if (_application.Session.DefaultStore.IsInstantSearchEnabled)
{
// Create a new explorer to display the Inbox as
// the current folder.
Outlook.Explorer explorer = _application.Explorers.Add(_inboxFolder, Outlook.OlFolderDisplayMode.olFolderDisplayNormal);
// Search for items from the manager marked important,
// from all folders of the same item type as the current folder, which is the MailItem item type.
explorer.Search(query, Outlook.OlSearchScope.olSearchScopeCurrentFolder);
// Any search results are displayed in that new explorer
// in an aggregated table view.
Outlook.TableView tableView = explorer.CurrentView as Outlook.TableView;
// Use GetTable of that table view to obtain items in that
// aggregated view in a Table object.
Outlook.Table table = tableView.GetTable();
resultsCount = table.GetRowCount();
while (!table.EndOfTable)
{
// Then display each row in the Table object
// that represents an item in the search results.
Outlook.Row nextRow = table.GetNextRow();
Outlook.MailItem mailItem = _application.Session.GetItemFromID(nextRow["EntryID"]) as Outlook.MailItem;
searchResults.Add(new Mail(mailItem?.Subject, mailItem?.SenderEmailAddress));
}
searchResults.GroupBy(m => m.SenderEmailAddress);
}
return searchResults;
}