I am trying to connect to Exchange web services to send email on behalf of a user through my own web service (ASP / WCF). My code works fine when working on a desktop PC, which can connect to the exchange server, but when working through the Internet, the exchange server cannot be accessed, so I'm trying to connect through my web server.
I am looking for ways to log in as a different user without using the Exchange Web Services simulation (since I was told not to use this unless there is another way) and without providing the user with a password.
I have the following code:
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
But this does not work due to an exception Unable to cast object of type 'System.Security.Cryptography.X509Certificates.X509Certificate' to type 'System.Net.ICredentials'..
- , X509 - Exchange, /