I try to connect to an Exchange mail account, but when I try to get messages, i get the “The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel” error.
Looking arround the Internet, I found that I have to use
Function CertificateValidationCallBack( _
ByVal sender As Object, _
ByVal certificate As X509Certificate, _
ByVal chain As X509Chain, _
ByVal sslPolicyErrors As SslPolicyErrors _
) As Boolean
ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf CertificateValidationCallBack)
I try the following to connect
Dim credential As System.Net.NetworkCredential = New System.Net.NetworkCredential(System.Configuration.ConfigurationManager.AppSettings(“readerusername”), System.Configuration.ConfigurationManager.AppSettings(“readerpassword”), “LAWOFFICE”)
Dim client As ExchangeWebServiceClient = New ExchangeWebServiceClient(“https://ip/owa”, credential)
eventlog1.WriteEntry(“Successfully connected to Microsoft Exchange server.”)
The problem is that, I cannot use ServicePointManager because in my code I get a build error that "Name ServicePointManager is not declared"
Could you please help me???
Thank you for inquiry.
ServicePointManager class exists in System.Net namespace and it needs to be imported in the project. I have attached a sample VB program to connect to Exchange Server, please try and see if it works at your end.
Thank you very much for your answer!!
I didn’t use the ServicePointManager with the correct declaration!