Free Support Forum -

Ho to connect to an Exchange server (with ExchangeClient object) using SSL (https)?

Hi, I want to connect to an exchange server 2003 via SSL.

I’ve tried this code (using https in the server uri):

Const mailboxUri As String = "https://myExchange2003Server/exchange/myUser"
Const username As String = "myUser"
Const password As String = "myPassword"
Const domain As String = "myDomain"

Sub test()

’ Create instance of ExchangeClient class by giving credentials
Dim credential As NetworkCredential = New NetworkCredential(username, password, domain)
Using client As ExchangeClient = New ExchangeClient(mailboxUri, credential)
End Using
Catch ex As Exception
End Try
End Sub

But I obtain this error:
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

Can be a problem in my exchange server (not well configured) or is there something wrong on my code?
What I need to do to connect to an exchange server via SSL? Using https in the uri is enough or I need to do something else? In your documentarion I’ve found nothing about SSL or server port for the ExchangeClient class.

Thank you!

Hi Alessandro,

Thank you for using Aspose.Email.

This error message appears if the Exchange Server has a self signed SSL certificate or it is expired. Please use the following approach to avoid such errors and let us know your feedback:

// register callback method for SSL validation event in main() or init()
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidationHandler;

// this event handler will be called when SSL certificate is verified
private static bool RemoteCertificateValidationHandler(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
return true; //ignore the checks and go ahead

OK, now it’s all clear for me!

Many thanks!


Hi Alessandro,

Thank you for the feedback and let us know if we can be of any additional help to you regarding any query/inquiry related to Aspose.Email. We’ll be glad to assist you further.