1

Java EWS API を使用して Exchange サーバー上のデフォルト以外のメールボックスを読み取りたいのですが、コードに何か問題があります。関連する部分の抜粋を次に示します。

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)

ところで。デフォルトのメールボックスを読んだり、メールを送信したりできます...

アドバイスいただけますか?前もって感謝します!

4

2 に答える 2

0

1 つのメールボックスにアクセスしようとしていると思いますが、別のアカウントの資格情報を使用しています。これは偽装によって解決できます。

EWS の新しいバージョンでは、これは Exchange サーバーの AD で解決するか、ConnectingSID プロパティをプログラムで設定することによって解決できます。私はおそらく 2 番目のものを頼りにして、さまざまな環境に合わせてプライマリ 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 のドキュメント

この記事によると、これは EWS 2007 SP1 でも利用できるようです。記事から、次のことに注意してください。

権限 "ms-Exch-EPI-Impersonation" を、偽装を行うサービス アカウントのクライアント アクセス サーバー上に設定する必要があります。さらに、サービス アカウントには、偽装する各メールボックスで "ms-Exch-EPI-May-Impersonate" 権限が付与されている必要があります。この権利は、ストア、ストレージ グループ、サーバー、または組織レベルで設定した場合、メールボックスに継承されます。

于 2013-08-13T13:45:21.543 に答える