question

AdamRobins-6968 avatar image
0 Votes"
AdamRobins-6968 asked AdamRobins-6968 answered

"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

office-outlook-itprooffice-vba-devoffice-exchange-server-connectivityoffice-exchange-server-dev
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @AdamRobins-6968

Do you encounter any issue connecting o365 mailboxes using Outlook client or OWA? Please note that our forum focuses on solving Exchange-related issues. And according to your description above, this seems to be more related to o365 integration and vb dev. So I would add some related tags, thanks for your understanding!

0 Votes 0 ·
AdamRobins-6968 avatar image
0 Votes"
AdamRobins-6968 answered

Process moved back to production server after upgrading to .Net 4.7.2. No failures in over two weeks. Considering issue resolved.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

CharlesEpocWaudby-9587 avatar image
0 Votes"
CharlesEpocWaudby-9587 answered CharlesEpocWaudby-9587 published

Had same issue, I think you need to change to TLS 1.2 as MS are deprecating 1.1 etc.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DavideGessati-3299 avatar image
0 Votes"
DavideGessati-3299 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AdamRobins-6968 avatar image
0 Votes"
AdamRobins-6968 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.