0 votes

Hi, some of our users are using office365 for emails. While most of the times, we are able to connect to the user's mailbox. But every day, we get "Authenticate as SSL client failed. You might be connecting to non SSL port" errors while connecting.

What I am unable to figure out is why it would give errors sometimes and work sometimes. Please help troubleshooting this issue.

Thanks
Sudhakar.

by (210 points)
reshown by
What is the inner exception?
Hi, the error is re-occuring. Here is the inner exception:

 Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.,   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
   at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)
This is clearly a network error (in particular SSL/TLS stream negotiation) - connection is lost - are you sure your router is not interfering?. If extending timeouts doesn't help, you can't do much. When you encounter this error you should simply try to connect again.

1 Answer

+1 vote

In general this error means that SslStream.AuthenticateAsClient method failed and threw an exception.

Are you absolutely sure you are using correct SSL ports for email protocols?

You should examine inner exception and stack trace, as those may include more information on why it happened.

You may consider extending the timeouts (by default those are set to 20 seconds):

imap.SendTimeout = TimeSpan.FromMinutes(1);
imap.ReceiveTimeout = TimeSpan.FromMinutes(1);
imap.ConnectSSL("server.example.com");
by (297k points)
Thank you. Increasing timeout helped.
...