"Authentication failed because the remote party has closed the transport stream" when connecting to the outlook.office365.com mail server.

AdamRobins-6968 96 Reputation points
2021-10-06T14:08:34.787+00:00

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

Outlook Management
Outlook Management
Outlook: A family of Microsoft email and calendar products.Management: The act or process of organizing, handling, directing or controlling something.
4,887 questions
Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
508 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,350 questions
{count} votes

3 additional answers

Sort by: Most helpful
  1. 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.

    0 comments No comments

  2. 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.

    0 comments No comments

  3. 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.

    0 comments No comments