Process moved back to production server after upgrading to .Net 4.7.2. No failures in over two weeks. Considering issue resolved.
"Authentication failed because the remote party has closed the transport stream" when connecting to the outlook.office365.com mail server.
I have a VB.Net console app that has been running successfully for five years. This app uses OpenPOP to retrieve the contents of an Office 365 mailbox and save the attachments to a Windows Server network share. Starting last week, I am seeing the error "Authentication failed because the remote party has closed the transport stream" when connecting to the Office 365 server. This does not happen every time. The app runs via SQL Server Agent every five minutes and fails only several times per day. Some times it fails several times per hour, but other days it may not fail at all, but is become more frequent. The Windows 2016 server is currently on .Net 4.5.2.
Example Code:
Dim client As New Pop3Client
System.Net.ServicePointManager.SecurityProtocol = Net.SecurityProtocolType.Tls12 ' I just added this, but it is not helping.
client.Connect("outlook.office365.com", 995, 1, 60000, 60000, New RemoteCertificateValidationCallback(AddressOf ValCert))
client.Authenticate("OPUserName", "OPPassword", AuthenticationMethod.UsernameAndPassword)
For i = 1 to client.GetMessageCount
...
...
Next
client.Disconnect()
client.Dispose()
Function ValCert(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslpolicyerrors As SslPolicyErrors) As Boolean
Return True
End Function
Beyond adding the explicit setting of TLS 1.2 I've not seen any other solutions to this issue. Any suggestions would be appreciated.
Full error:
10/5/2021 1:45:00 PM Type: I UMCAMail Start ---------------------------------
10/5/2021 1:45:00 PM Type: E Function Main - AppID: 0 Message: Authentication failed because the remote party has closed the transport stream. StackTrace: at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
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.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost)
at OpenPop.Pop3.Pop3Client.Connect(String hostname, Int32 port, Boolean useSsl, Int32 receiveTimeout, Int32 sendTimeout, RemoteCertificateValidationCallback certificateValidator)
at UMCAMail.Module1.Main(String[] Args) in D:\arobins\Dropbox\ARF\Documents\Visual Studio Projects\Console Apps\UMCAMail\UMCAMail\Module1.vb:line 57
3 additional answers
Sort by: Most helpful
-
Charles Epoc Waudby 1 Reputation point
2021-10-27T21:24:32.153+00:00 Had same issue, I think you need to change to TLS 1.2 as MS are deprecating 1.1 etc.
-
Davide Gessati 1 Reputation point
2021-10-28T15:56:05.367+00:00 I have the same issue.
I have a service that tries to connect every 10 minutes.
Sometimes it works, but most of the times it fails with error 'Authentication failed because the remote party has closed the transport stream'
Me too have tried to add System.Net.ServicePointManager.SecurityProtocol = Net.SecurityProtocolType.Tls12,
but it seems that OpenPop.Pop3.Pop3Client doesn't care. the problem persists. -
AdamRobins-6968 96 Reputation points
2021-10-28T16:00:43.87+00:00 I moved the process to another server running .Net 4.7.2 (versus the production server which is on .Net 4.5.2) . The error has not occurred in over two weeks. I plan to upgrade the production .Net version and will move the process back.