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

K Amen 1 Reputation point
2021-05-18T22:28:53.447+00:00

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, IDictionary2 parameters) +224 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +27
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +57
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +260 System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +26 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor, IDictionary2 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>b__5() +34 System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +16 System.Web.Mvc.Async.<>c__DisplayClass81.<BeginSynchronous>b__7(IAsyncResult _) +15
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +59
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +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

Internet Information Services
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,252 questions
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,234 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sam Wu-MSFT 7,036 Reputation points Microsoft Vendor
    2021-05-19T08:05:36.817+00:00

    Hi @K Amen

    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 people found this answer helpful.

  2. Artemiy Moroz 271 Reputation points
    2021-05-19T16:10:19.227+00:00

    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.

    1 person found this answer helpful.