Exchange Web サービスに接続して、自分の Web サービス (ASP/WCF) を介してユーザーの代わりに電子メールを送信しようとしています。Exchange サーバーに接続できるデスクトップ PC で実行している場合はコードが正常に動作しますが、インターネット経由で操作している場合は Exchange サーバーにアクセスできないため、代わりに Web サーバー経由で接続しようとしています。
Exchange Web サービスの偽装を使用せずに別のユーザーとしてログインする方法を探しています (他の方法がまったくない場合を除き、使用しないように言われているため)。
次のコードがあります。
Dim service As New Microsoft.Exchange.WebServices.Data.ExchangeService(Microsoft.Exchange.WebServices.Data.ExchangeVersion.Exchange2007_SP1)
Dim emailAddress As String = "example@example.com"
System.Net.ServicePointManager.ServerCertificateValidationCallback = AddressOf CertificateValidationCallBack
Dim cert As New System.Security.Cryptography.X509Certificates.X509Certificate2(HttpContext.Current.Request.ClientCertificate.Certificate)
service.Credentials = New Microsoft.Exchange.WebServices.Data.WebCredentials(New System.Security.Cryptography.X509Certificates.X509Certificate())
service.UseDefaultCredentials = False
Unable to cast object of type 'System.Security.Cryptography.X509Certificates.X509Certificate' to type 'System.Net.ICredentials'.
しかし、これは例外のため機能しません。
ネットワーク資格情報またはユーザー名/パスワードを使用するのではなく、X509 証明書を使用して Exchange Web サービスに対して認証する方法を教えてもらえますか?