[英]Wrong mailbox items being retrieved using Exchange Web Services managed API in C#
I'm trying to retrieve Inbox items from a specific mailbox (in which i have permissions), using Exchange Web Services managed API. 我正在尝试使用Exchange Web服务托管API从特定邮箱(我有权限)中检索收件箱项目。 I've tested the code first using my own email address via AutodiscoverUrl, and it works fine.
我首先使用我自己的电子邮件地址通过AutodiscoverUrl测试了代码,它运行正常。 However when i tried using the other email address, EWS still retrieves my own inbox items.
但是,当我尝试使用其他电子邮件地址时,EWS仍会检索我自己的收件箱项目。 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);
The e-mail address given to AutodiscoverUrl
has nothing to do with which mailbox you are binding to. 提供给
AutodiscoverUrl
的电子邮件地址与您绑定到的邮箱无关。
There are (at least) two ways to get the inbox items from another users mailbox: Delegate access and impersonation. 有(至少)两种方法从另一个用户邮箱获取收件箱项目:委派访问权限和模拟。
If you have delegate access to the other users mailbox, you can specify the mailbox as a parameter in the call to FindItems
: 如果您具有其他用户邮箱的委派访问权限,则可以在对
FindItems
的调用中将邮箱指定为参数:
FindItemsResults<Item> findResults = ex.FindItems(
new FolderId(WellKnownFolderName.Inbox, new Mailbox("someothermailbox@company.com")),
new ItemView(10));
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: 如果您具有模拟其他用户的权限 ,则可以在连接到EWS时模拟其他用户,并且以下对
FindItem
调用将在模拟用户的收件箱中起作用:
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));
Disclaimer: I have written the above code without actually testing it on a real Exchange server. 免责声明:我已编写上述代码,但未在真正的Exchange服务器上进行实际测试。
if you want to send email using only delegates permission save the email first before sending it. 如果您只想使用代理人发送电子邮件权限,请在发送之前先保存电子邮件。 it will set the smtp address that is required to send the message.
它将设置发送消息所需的smtp地址。
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new WebCredentials("user1", "1234", "domain.com");
service.AutodiscoverUrl("user2@domain.com");
EmailMessage email = new EmailMessage(service);
email.ToRecipients.Add("user2@domain.com");
email.Subject = "HelloWorld";
email.Body = new MessageBody("Sent by using the EWS Managed API");
//save it first!
email.Save(new FolderId(WellKnownFolderName.Drafts, "user1@domain.com"));
email.Send();
i used it to avoid this error: "When making a request as an account that does not have a mailbox, you must specify the mailbox primary SMTP address for any distinguished folder Ids." 我使用它来避免此错误:“当作为没有邮箱的帐户发出请求时,您必须为任何可识别的文件夹ID指定邮箱主SMTP地址。”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.