使用C#中的Exchange Web Services托管API检索到错误的邮箱项目 [英] Wrong mailbox items being retrieved using Exchange Web Services managed API in C#

查看:67
本文介绍了使用C#中的Exchange Web Services托管API检索到错误的邮箱项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用Exchange Web服务托管API从特定的邮箱(我拥有权限)中检索收件箱项目。我已经通过AutodiscoverUrl使用自己的电子邮件地址对代码进行了测试,并且效果很好。但是,当我尝试使用其他电子邮件地址时,EWS仍会检索我的拥有收件箱项目。这是由于缓存还是其他原因?

I'm trying to retrieve Inbox items from a specific mailbox (in which i have permissions), using Exchange Web Services managed API. I've tested the code first using my own email address via AutodiscoverUrl, and it works fine. However when i tried using the other email address, EWS still retrieves my own inbox items. Is this due to a cache or something?

我的代码如下:

My code is as follows:

    ExchangeService ex = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
    ex.AutodiscoverUrl("someothermailbox@company.com");

    FindItemsResults<Item> findResults = ex.FindItems(WellKnownFolderName.Inbox, new ItemView(10));

    foreach (Item item in findResults.Items)
         Console.WriteLine(item.Subject);


推荐答案

给<$ c $的电子邮件地址c> AutodiscoverUrl 与绑定到的邮箱无关。

The e-mail address given to AutodiscoverUrl has nothing to do with which mailbox you are binding to.

(至少)有两种方法可以从另一个用户的邮箱中获取收件箱项目:委托访问和模拟。

There are (at least) two ways to get the inbox items from another users mailbox: Delegate access and impersonation.

如果您具有对其他用户邮箱的代理访问权限,则可以在调用 FindItems

If you have delegate access to the other users mailbox, you can specify the mailbox as a parameter in the call to FindItems:

FindItemsResults<Item> findResults = ex.FindItems(
    new FolderId(WellKnownFolderName.Inbox, new Mailbox("someothermailbox@company.com")), 
    new ItemView(10));

如果您拥有模拟其他用户的权限,您可以在连接到EWS时模拟其他用户,并且随后对 FindItem 将在模拟用户的收件箱上起作用:

If you have the permissions to impersonate the other user, you can impersonate the other user when connecting to the EWS and the following call to FindItem will work on the inbox of the impersonated user:

ExchangeService ex = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
ex.AutodiscoverUrl("someothermailbox@company.com");
ex.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "someothermailbox@company.com");
ItemsResults<Item> findResults = ex.FindItems(WellKnownFolderName.Inbox, new ItemView(10));

免责声明:我编写了以上代码,但并未在实际的Exchange服务器上进行实际测试。

Disclaimer: I have written the above code without actually testing it on a real Exchange server.

这篇关于使用C#中的Exchange Web Services托管API检索到错误的邮箱项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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