web-dev-qa-db-ja.com

c#はExchangeサーバーからプログラムで電子メールを読み取る

ウェブで検索すると、「プログラムでメールを読む方法」に対する非常に簡単な答えが見つかります...すべてのウェブサイトはこのページのようにほとんど同じことを説明しています。 http://omegacoder.com/?p=454

// depends from Exchange server version      
        service.Credentials = new NetworkCredential("MDR", "password", "zzz");
        service.AutodiscoverUrl("[email protected]");
        object o = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
        FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
        foreach (Item item in findResults.Items)
        {
            Console.WriteLine(item.Subject);
        }

autodiscoverURL行を実行すると失敗します。エラーには、「自動検出サービスが見つかりませんでした」と表示されます。

だから私はさらにグーグルでマイクロソフトからこのサイトを見つけました https://www.testexchangeconnectivity.com/#&&/wEXAQUBcwUBME93h2+JjI0+MV2gTqcRL0g43z9m ここであなたはあなたのメールサーバーをテストすることができます....私が合格するとパラメータ以下のエラーが発生します...

しかし、私はまだ問題が何であるかを理解していませんか? DNSにレコードを追加する必要がありますか?誰かが助けることができますか?

Attempting to test potential Autodiscover URL https://autodiscover.zzz.be/AutoDiscover/AutoDiscover.xml
 Testing of this potential Autodiscover URL failed.
 Test Steps
 Attempting to resolve the Host name autodiscover.ncb.be in DNS.
 The Host name resolved successfully.
 Additional Details
 IP addresses returned: 213.246.192.205

Testing TCP port 443 on Host autodiscover.ncb.be to ensure it's listening and open.
 The specified port is either blocked, not listening, or not producing the expected response.
  Tell me more about this issue and how to resolve it
 Additional Details
 A network error occurred while communicating with the remote Host.
Exception details:
Message: No connection could be made because the target machine actively refused it 213.246.192.205:443
Type: System.Net.Sockets.SocketException
Stack trace:
at System.Net.Sockets.TcpClient.Connect(String hostname, Int32 port)
at Microsoft.Exchange.Tools.ExRca.Tests.TcpPortTest.PerformTestReally()




Attempting to contact the Autodiscover service using the HTTP redirect method.
 The attempt to contact Autodiscover using the HTTP Redirect method failed.
 Test Steps
 Attempting to resolve the Host name autodiscover.zzz.be in DNS.
 The Host name resolved successfully.
 Additional Details
 IP addresses returned: 213.246.192.205

Testing TCP port 80 on Host autodiscover.zzz.be to ensure it's listening and open.
 The port was opened successfully.
ExRCA is checking the Host autodiscover.zzz.be for an HTTP redirect to the Autodiscover service.
 ExRCA failed to get an HTTP redirect response for Autodiscover.
 Additional Details
 A Web exception occurred because an HTTP 404 - NotFound response was received from IIS7.



Attempting to contact the Autodiscover service using the DNS SRV redirect method.
 ExRCA failed to contact the Autodiscover service using the DNS SRV redirect method.
 Test Steps
 Attempting to locate SRV record _autodiscover._tcp.ncb.be in DNS.
 The Autodiscover SRV record wasn't found in DNS.
  Tell me more about this issue and how to resolve it
9
ethem

Exchangeサーバーのアドレスが既にわかっている場合は、必ずしも自動検出を使用する必要はありません。代わりに次を試してください(詳細については、 ここ を参照してください:

service.Url = new Uri("https://hostname/EWS/Exchange.asmx");

「hostname」をExchangeサーバーのホスト名に置き換えます。

17
Can Gencer

私はあなたが今この時までに解決策を持っているべきであることを望みます。これは、この投稿にぶつかった人を助けるためだけのものです。 technet article のいずれかで解決策を見つけました。私は自分に合うようにひねり、うまく機能しています。

コードの行を次のように置き換えるだけです。

service.AutodiscoverUrl("[email protected]",
delegate
{
     return true;
});

私は他のいくつかの問題を抱えていましたが、このビットとは関係ありませんでした。

ハッピーコーディング、

サンジェイ。

2
Sanjay Zalke

AutoDiscoverでも同じ問題が発生しました。必須ではありません。次のようにURLを指定できます。

    Uri myUri = new Uri("https://Hostname/ews/exchange.asmx");
    userData.AutodiscoverUrl = myUri;
    service.Url = myUri;

ホスト名として、192.168.100.10のようなサーバーIPアドレスを入力できます

または、Outlookを使用している場合にExchangeサーバーのホスト名(実際には使用するURL全体)を確認するには、日付と時刻が表示されているコンピューターのスタートバーに移動し、Outlookアイコンを見つけます。Ctrlキーを押したままにします。 + Outlookアイコンを右クリックし、[電子メールの自動構成のテスト]をクリックします

[自動検出を使用する]チェックボックスをオンにします。そのExchangeServerでホストされている電子メールアドレスとそのパスワードを入力すると、一連のURLを受け取ります。 「AvailabilityServiceURL」と書かれた1を使用してください

1
6dev6il6

渡される資格情報には、特定のExchangeメールボックス/サーバーへのアクセス許可が必要であると考えてください。私の場合、適切に許可された別の資格情報のセットを使用すると機能しますが、機能させようとしているサービスアカウントには使用できません。アカウントに許可が必要なものを正確に見つけたら、ここで更新します。

更新:私の問題は、サービスアカウントが、Exchange 2007インスタンスが実行されているドメインとは異なるドメインからのものであるということでしたが、2つの間に信頼関係があります。これは、Exchange 2007で、フォレスト内のアカウントを検索する方法に関する既知の問題として文書化されていることがわかりました。最終的に、Exchangeサーバーが置かれているドメインに同一のサービスアカウント(名前/パス)を作成し、ユーザー名を{exchange_domain} {service_account_name}として指定する必要がありました。 EWSを呼び出すWindowsサービスは、{original_domain} {service_account_name}として実行されます。

参考までに、例外は次のとおりです。Microsoft.Exchange.WebServices.Data.ServiceResponseException:呼び出し元アカウントの有効なActiveDirectory情報を取得できませんでした。有効なActiveDirectoryアカウントであることを確認してください。

0
Chris Amelinckx