gpt4 book ai didi

Java EWS API - 读取非默认邮箱

转载 作者:行者123 更新时间:2023-12-01 04:28:44 26 4
gpt4 key购买 nike

我想使用 Java EWS API 读取交换服务器上的非默认邮箱,但我的代码有问题。以下是相关部分的摘录:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
ExchangeCredentials credentials = new WebCredentials("<user>", "<pass>");
service.setCredentials(credentials);
service.setUrl(new URI("https://<URL>/EWS/Exchange.asmx"));
ItemView iview = new ItemView(3);
Mailbox mb = new Mailbox();
mb.setAddress("<mailbox_address>");
FolderId folderId = new FolderId(WellKnownFolderName.Root, mb);
FindItemsResults<Item> findResults = service.findItems(folderId, iview);

错误信息是:

Exception in thread "main" microsoft.exchange.webservices.data.EWSHttpException: Connection not established
at microsoft.exchange.webservices.data.HttpClientWebRequest.throwIfConnIsNull(Unknown Source)
at microsoft.exchange.webservices.data.HttpClientWebRequest.getResponseHeaders(Unknown Source)
at microsoft.exchange.webservices.data.ExchangeServiceBase.processHttpResponseHeaders(Unknown Source)
at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(Unknown Source)
at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(Unknown Source)
at microsoft.exchange.webservices.data.ExchangeService.findItems(Unknown Source)
at microsoft.exchange.webservices.data.ExchangeService.findItems(Unknown Source)

顺便说一句。我能够读取我的默认邮箱、发送电子邮件等...

您能给点建议吗?提前致谢!

最佳答案

我相信您正在尝试访问一个邮箱,但使用另一个帐户的凭据。这可以通过模拟来解决。

在较新版本的 EWS 中,可以解决此问题 in AD on the exchange serverby programmatically setting the ConnectingSID property 。我可能会选择第二个,并为不同的环境配置主 SMTP 地址。

以下是在 C# 中使用 EWS 2010 的代码示例,因此您可能必须使用 setCredentials(credentials) 来代替,依此类推:

代码示例 EWS 2010

ExchangeServiceBinding binding = new ExchangeServiceBinding();
// Use this class instead of ExchangeService (!)
binding.Credentials = credentials;
// etc

binding.ExchangeImpersonation = new ExchangeImpersonationType();
binding.ExchangeImpersonation.ConnectingSID = new ConnectingSIDType();
binding.ExchangeImpersonation.ConnectingSID.PrimarySmtpAddress = "<mailbox_address>";

EWS 2007 文档

根据 this article 的说法,这似乎也应该在 EWS 2007 SP1 中提供。 。请注意,文章中指出:

you have to set to rights “ms-Exch-EPI-Impersonation” must be on the Client Access server for the service account which will do the impersonation. Additionally the service account will have to have the “ms-Exch-EPI-May-Impersonate” right granted to it on each mailbox it will impersonate. This right is inherited down to mailboxes if you were to set it at the store, storage group, server, or organizational level.

关于Java EWS API - 读取非默认邮箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18203782/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com