Authentication failed because the remote party has closed the transport stream

tuyen1644 21 Reputation points
2021-10-12T01:22:09.097+00:00

I have application auto daily send email using smtpclient, it's still running OK before 1-Oct-2021. But from 1-Oct-2021, it send missing email, i use try catch to debug this and get exception below:
139617-errorsendemail.jpg

Please, give me a solution other than having to set up TLS1.2 in the application.
Thanks!

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,245 questions
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,886 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,349 questions
{count} votes

8 answers

Sort by: Most helpful
  1. KillboyPowerhead 1 Reputation point
    2021-10-13T08:56:00.637+00:00

    Same problem here.
    Mail sending worked flawlessy unitl 1st oct. 2021 using SmtpClient in our applications targeting Framework 4.0. Unfortunately in the last days many of our customers using Office365 reported "Authentication failed because the remote party has closed the transport stream" error during some mail sending sessions.
    It's not a constant error, after retrying a few times it works.
    Our customers are mainly distributed throughout Italy, so i don't think the error to be related to physical connection issues.

    We use "SmtpClient" like this, by assigning "SecurityProtocolType" casting 768 and 3072 to enum (since our platform require targeting Framework 4.0, we don't have Tls11 and Tls12 enum value):

    ServicePointManager.SecurityProtocol =
    SecurityProtocolType.Tls Or
    DirectCast(768, SecurityProtocolType) Or
    DirectCast(3072, SecurityProtocolType)
    ServicePointManager.ServerCertificateValidationCallback = Function() True

    ClientMail = New SmtpClient()
    ClientMail.TargetName = "STARTTLS/smtp.office365.com"
    ClientMail.EnableSsl = True
    ClientMail.DeliveryMethod = SmtpDeliveryMethod.Network

    It has always worked but now we are having a lot of troubles.
    Any help?

    0 comments No comments

  2. Evan Knutson 6 Reputation points
    2021-10-14T16:36:24.213+00:00

    I am also having the same issue. It's intermittent too. I also upgraded to TLS 1.2 by upgrading to .NET 4.5.2.

    0 comments No comments

  3. Dario Graça 1 Reputation point
    2021-10-27T15:19:50.597+00:00

    Hello,

    I was able to fix this by adding the following AppContext.SetSwitch to my code:
    ...
    AppContext.SetSwitch("Switch.System.Net.DontEnableSystemDefaultTlsVersions", false);
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Ssl3;
    ...

    Using FW 4.6.2

    0 comments No comments