在 Outlook 中执行搜索查询 [英] Perform search query in Outlook

查看:46
本文介绍了在 Outlook 中执行搜索查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想知道是否可以从我的 WinForms 应用程序向 Outlook 2010 发送搜索查询.也就是说,不是像我一直在四处搜索一样搜索 .PST 文件,而是尝试在 Outlook 中显示结果列表,就像我自己在搜索框中键入一样.

Hello I am wondering if it is possible to send a search query to Outlook 2010 from my WinForms app. That is, not search the .PST file as I've been searching around and finding, I'm trying to display a list of results in Outlook as if I typed in the search box myself.

如果可能,任何示例代码都会有所帮助.此外,是否可以直接在所有邮件项目中执行搜索,而通常在进行搜索时它会梳理当前文件夹.谢谢.

If it is possible, any example code would be helpful. Additionally, is it possible to directly perform a search in All Mail Items versus, usually when you do a search it combs the current folder. Thanks.

推荐答案

如果您想访问 Outlook 数据(例如邮件),您必须添加对 Microsoft Outlook X.X 对象库的 COM 引用.

If you want to access the Outlook data (mail for example) you have to add a COM reference to the Microsoft Outlook X.X Object library.

对于 Outlook,您可以使用 COM 互操作.打开添加引用"对话框并选择 .NET 选项卡,然后添加对 Microsoft.Office.Interop.Outlook 程序集的引用.

For Outlook you can use COM interop. Open the Add Reference dialog and select the .NET tab, then add a reference to the Microsoft.Office.Interop.Outlook assembly.

之后不要忘记将命名空间Microsoft.Office.Interop.Outlook"添加到您的 using 子句中.

Afterwards don't forget to add the namespace "Microsoft.Office.Interop.Outlook" to your using clauses.

现在您可以创建 Outlook 应用程序对象的实例:

Now you can create an instance of the Outlook application object:

Microsoft.Office.Interop.Outlook.Application outlook;
outlook = new Microsoft.Office.Interop.Outlook.Application(); 

让我们对您的收件箱进行查询:

Let's perform a query on your inbox:

MAPIFolder folder =
    outlook.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderInbox);
    IEnumerable<MailItem> mail = 
        folder.Items.OfType<MailItem>().Where(m => m.Subject == "Test").Select(m => m);

您指定要搜索的文件夹作为 GetDefaultFolder(...) 方法的参数.您可以指定收件箱以外的其他文件夹.

You specify the folder you want to search as a parameter for the GetDefaultFolder(...) method. You can specify other folder besides the inbox.

  • olFolderSentMail
  • olFolderOutbox
  • olFolderJunk
  • ...

在 MSDN 上查看每个可能的值:

Check out each possible value on MSDN:

OlDefaultFolders 枚举

Stefan Cruysbergs 创建了一个 OutlookProvider 组件,它充当Outlook 应用程序对象的包装器.您可以使用 LINQ 查询此提供程序并检索联系人、邮件等数据.只需 下载他的代码并检查出来.这应该足以让您入门.

Stefan Cruysbergs created an OutlookProvider component which acts as a wrapper for the Outlook application object. You can use LINQ to query this provider and retrieve data such as the contacts, mail...etc.. Just download his code and check it out. This should be enough to get you started.

这篇关于在 Outlook 中执行搜索查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆