question

KhalidAmen-9996 avatar image
0 Votes"
KhalidAmen-9996 asked Klearndaily-7787 commented

Authentication failed because the remote party has closed the transport stream.

This is what got when I try to reset a password and an authentication email. Is the issue with ServicePointManager.SecurityProtocol or with SmtpClient? Where do I need to change it or set it? The application is running in IIS and build in VS 2010.

[IOException: Authentication failed because the remote party has closed the transport stream.]
System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) +6707868
System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) +139
System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) +297
System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) +51
System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) +166
System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) +573
System.Net.TlsStream.CallProcessAuthentication(Object state) +44
System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) +195
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) +22
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) +67
System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) +803
System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) +54
System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size) +105
System.Net.Mail.SmtpConnection.Flush() +30
System.Net.Mail.ReadLinesCommand.Send(SmtpConnection conn) +16
System.Net.Mail.EHelloCommand.Send(SmtpConnection conn, String domain) +22
System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) +1137
System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) +237
System.Net.Mail.SmtpClient.GetConnection() +47
System.Net.Mail.SmtpClient.Send(MailMessage message) +1630

[SmtpException: Failure sending mail.]
System.Net.Mail.SmtpClient.Send(MailMessage message) +1998
Acs.Mail.SendErrorNotice(String strErrorMessage) in C:\Users\CR\Documents\Visual Studio 2010\Projects\WebForm2010\abc\Acs.Mail.cs:59
WebForm.Controllers.AccountController.ResetPassword(String email) in C:\Users\CR\Documents\Visual Studio 2010\Projects\WebForm2010\WebForm\Controllers\AccountController.cs:328
lambda_method(Closure , ControllerBase , Object[] ) +104
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +19
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +224
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.<>c_DisplayClass15.<InvokeActionMethodWithFilters>b12() +57
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +260
System.Web.Mvc.<>c
DisplayClass17.<InvokeActionMethodWithFilters>b14() +26
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +205
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +326
System.Web.Mvc.Controller.ExecuteCore() +109
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +92
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +12
System.Web.Mvc.<>c
DisplayClassb.<BeginProcessRequest>b5() +34
System.Web.Mvc.Async.<>c
DisplayClass1.<MakeVoidDelegate>b0() +16
System.Web.Mvc.Async.<>c
DisplayClass8`1.<BeginSynchronous>b7(IAsyncResult ) +15
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +59
System.Web.Mvc.<>c_DisplayClasse.<EndProcessRequest>bd() +48
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b
_0(Action f) +12
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +24
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +66
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +11
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9850009
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +50
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +163

dotnet-csharpwindows-server-iisdotnet-aspnet-mvc
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.

SamWu-MSFT avatar image
0 Votes"
SamWu-MSFT answered SamWu-MSFT commented

Hi @KhalidAmen-9996

You may get this error when trying to call an external API. This error is related to the Security Protocol Type, it is most likely caused by your application's default security protocol type being set too low, A lot of external APIs now expect requests using TLS 1.2 or above.

You can easily set the SecurityProtocol in your application by adding this line:

 ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

This can be added just before you call the api, or it can even be added in the application start method.

If you don't have all of these options available to you, maybe you are running a .NET 4.0 application, you can also set it like this:

 ServicePointManager.SecurityProtocol = (SecurityProtocolType)48 | (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;

You also don't have to include them all, you can take out the ones you don't need.


If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


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

Thank you for your response. The application is written in MVC VS2010. The API is local, not external, and it is in AccountController. I use razer for the front end to call ResetPassword method. Should I place the line inside the method? Also, you mentioned I can add the line in the application start, Can I add it in Application_Start() method in Global.asax.cs file? Can I add it in web.config, and how?

0 Votes 0 ·

@KhalidAmen-9996 I suggest you try it first and then discuss it when you get a problem, because it is difficult for me to reproduce your problem.

0 Votes 0 ·
ArtemiyMorozUA avatar image
0 Votes"
ArtemiyMorozUA answered Klearndaily-7787 published

hi there! The problem is rather easy to solve. Please read solution here:

The problem may arise when you are trying to call TLS protocol version 1.2 from .NET 4.0 C# application.


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

Thank you. I have checked my machine. It has Framework 4.8 installed on it. This kind of an old application written in VS 2010 and it is in the IIS server. If I do any changes to the codes, I have to build them. I do not have that env anymore or cannot install it on my machine. The only place I see is Global.asax.cs under Application_start method. Can I fix the issue in the IIS server? or how do I build the application without using VS 2010?

0 Votes 0 ·

Thank you very much! you saved my life.

0 Votes 0 ·