question

tuyen1644-8024 avatar image
3 Votes"
tuyen1644-8024 asked MaximeGagnon-9572 commented

Authentication failed because the remote party has closed the transport stream

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!

dotnet-csharpoffice-outlook-itprooffice-exchange-server-connectivityoffice-exchange-server-dev
errorsendemail.jpg (37.0 KiB)
· 6
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.

Even I'm facing the same issue:

Error log

Failure Sending mail.
Authentication failed because the remote party has closed the transport stream

Not possible to connect to the mail server smpt.office365.com on port 587"

The email Encryption method used is TLS 1.2
PORT:587
SERVER: smpt.office365.com
SSL: yes
Kindly advise, as the issue occurs after 1st oct 2021

2 Votes 2 ·

@tuyen1644-8024
Why don't you want to set TLS to 1.2?
This error is caused by this reason in many cases, just set it to solve the problem:

 ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

If it doesn't work for you, please provide a code example so that we can quickly reproduce your problem.

0 Votes 0 ·

I use automatic mailing in many applications, so I can't update all of them, I want another solution that doesn't have to update the entire application in use. Thanks!

1 Vote 1 ·

@tuyen1644-8024 , As the Timon said, Could you provide a code example instead of picture in your question? It will be better for us to make a test.

0 Votes 0 ·
Show more comments
AndyDavid avatar image
1 Vote"
AndyDavid answered tuyen1644-8024 commented

Is MFA required for this account? If so, that is expected.

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

Do you mean to deactivate MFA from office365 or enable it?

0 Votes 0 ·

Deactivate it for that account and allow it to use Basic Auth for SMTP

0 Votes 0 ·

I use the account used to send emails that don't have MFA set up, so it's not because of MFA!

0 Votes 0 ·
AgaveJoe avatar image
0 Votes"
AgaveJoe answered VaishnavP-9935 commented

According to the MS 365 docs, deprecation of TLS 1.0 and 1.1 started in 2020. Also, according to the docs you can sent unencrypted SMTP which is not recommended though. The best approach is upgrading your systems/software to TLS 1.2.

Preparing for TLS 1.2 in Office 365 and Office 365 GCC



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

@AgaveJoe Yes, The Application's supports only TLS 1.0 and that has to be upgraded to TLS 1.2.

0 Votes 0 ·
KillboyPowerhead-9099 avatar image
0 Votes"
KillboyPowerhead-9099 answered

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?


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.

EvanKnutson-3861 avatar image
0 Votes"
EvanKnutson-3861 answered EvanKnutson-3861 published

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.

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.

MaximeGagnon-9572 avatar image
1 Vote"
MaximeGagnon-9572 answered MaximeGagnon-9572 commented

Same error here as well with an app developed for thousands of customers. We receive an unusual number of calls of very angry customers regarding this issue which is intermittent.

Of course I can't ask my customers to simply use another email of different providers as they use the same address for numerous years now or use paid office365 accounts...

I also made sure we use compatible version of TLS, and even with 1.1 or 1.2 , it doesn't always work.

Clearly something's wrong with Microsoft SMTP servers...

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

Any luck so far? I'm dealing with this same issue. Our ERP software was built on TLS 1.0 and 1.1 and now the system is only sending emails out intermittently. It's bringing our business to a halt.

0 Votes 0 ·

No luck.
It seems Microsoft is indeed migrating all their SMTP servers to TLS 1.2 only. So Most attempts with TLS 1.0 or TLS 1.1 will simply not work from what I understand.

It seems the Framework used and the code has both to be updated to take TLS 1.2 into consideration as well.

0 Votes 0 ·
EvanKnutson-3861 avatar image
1 Vote"
EvanKnutson-3861 answered

An update on my end. The issue is resolved. Forcing TLS1.2 was the fix. I upgraded from .NET 2... to .NET v4.0.30319 and set the below:

         ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12; 
         SmtpClient.TargetName = "STARTTLS/" + EmailServer; 

I then had issues with registering the new .dll (i spoke incorrectly in my comment above). So when I thought the switch the TLS1.2 was not the fix, that was incorrect, the issue was that the .dll was not updating in the gac. I had to use an updated version of regasm.exe, found an updated version of gacutil.exe and also updated gacutil.exe.config.

so for example I am using this to register:
%windir%\Microsoft.NET\Framework\v4.0.30319\regasm.exe "C:\Program Files (x86)[app directory here]\DNeMailer.dll" /tlb:"C:\Program Files (x86)[app directory here]\DNeMailer.tlb"

And then to install into the gac. I had to update the version of .NET referenced in gacutil.exe.config.
"C:\Program Files (x86)[app directory here]\gacutil.exe" /i "C:\Program Files (x86)[app directory here\DNeMailer.dll"

It became obvious to me that the .dll was not updating when I was not able to uninstall the .dll from C:\Windows\assembly\

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.

SubhiAlmohtasib-8363 avatar image
2 Votes"
SubhiAlmohtasib-8363 answered tuyen1644-8024 commented

Hello All,

I was facing the same issue until I upgraded the .NET version to 4.6 instead of 4.5. Please refer to this answer here
https://stackoverflow.com/a/45442874/9050439

Hopefully it helps you.

Thanks

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

Thank you...! Currently, I'm using .net 4.7.2 and still getting this error

0 Votes 0 ·
DarioGraa-6116 avatar image
0 Votes"
DarioGraa-6116 answered

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

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.