使用EWS API搜索不同的用户邮箱

问题描述:

我们正在开发一个模块,其主要目标是跟踪和收集有关损坏检查(保险市场)的信息.每个案例都有一个代码(例如L000525).每个案例可以由几个人处理.与特定案例有关的所有电子邮件都在主题中包含案例代码.

We are developing a module with the main goal being to track and collect information about damage inspections (insurance market). Each case has a code (e.g. L000525). Each case could be managed by several people. All the emails related to a specific case include the case code in the subject.

我们要做的是收集并显示与每个特定案例有关的传入和发送电子邮件.

What we want to do is to collect and show the incoming and sent emails related to each specific case.

想法是,任何用户都可以打开案例管理"窗口,选择特定案例,然后获取所有相关信息(当然包括电子邮件).

The idea is that any user can open a "Case management" window, select an specific case, and then get all the related information (including the emails of course).

我们必须在大约20个用户的邮箱中找到电子邮件.所以问题是:

We have to find the emails into the the mailboxes of around 20 users. So the questions are:

  • 哪种方法更好?会消耗很多时间和资源吗?

我们在Exchange世界中是新手,因此我们正在考虑模仿Exchange,但我们不确定.该模块是在Silverlight 3,WCF,SQL Server + Exchange 2007中开发的.

We are new in the Exchange world so we are thinking Exchange impersonation, but we are not sure at all. The module is developed in Silverlight 3, WCF, SQL Server + Exchange 2007.

如果用于连接到EWS的凭据具有访问用户邮箱的权限,那么您应该能够执行以下操作:

If the credentials used to connect to EWS have rights to access a user's mailbox then you should be able to do something like this:

var service = new ExchangeService();
service.Credentials = new WebCredentials("user_with_access@example.com", "password");
service.AutodiscoverUrl("a_valid_user@example.com");

var userMailbox = new Mailbox("target_user@example.com");
var folderId = new FolderId(WellKnownFolderName.Inbox, userMailbox);

var itemView = new ItemView(20);   // page size
var userItems = service.FindItems(folderId, itemView);

foreach (var item in userItems)
{
    // do something with item (nb: it might not be a message)
}

就是这样.哇,我的第一个答案!

That's it. Wow, my first SO answer!