0

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.<>cDisplayClass17.<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.<>cDisplayClassb.<BeginProcessRequest>b5() +34
System.Web.Mvc.Async.<>cDisplayClass1.<MakeVoidDelegate>b0() +16
System.Web.Mvc.Async.<>cDisplayClass8`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
  • 59
  • 4

1 Answers1

0

Here is the ResetPassword method, I have checked that IIS using Framework 4.0 in the windows server.

public ActionResult ResetPassword(string email)
        {
            if (ModelState.IsValid)
            {
                string strUserName = Membership.GetUserNameByEmail(email);
                if (String.IsNullOrEmpty(strUserName))
                {
                    return RedirectToAction("ResetPasswordEmailSent");
                }
                MembershipUser mu = Membership.GetUser(strUserName);
                if (mu == null)
                {
                    return RedirectToAction("ResetPasswordEmailSent");
                }

                // Format Mail
                try
                {

                    System.Security.Cryptography.RandomNumberGenerator rng = System.Security.Cryptography.RNGCryptoServiceProvider.Create();
                    byte[] abRandom = new byte[36];
                    rng.GetNonZeroBytes(abRandom);
                    string strCode = Convert.ToBase64String(abRandom);
                    strCode = strCode.Replace("/", "");
                    strCode = strCode.Replace("+", "");
                    WebFormPasswordReset wfpr = new WebFormPasswordReset { strCode = strCode, dtCreated = DateTime.UtcNow, strUserName = mu.UserName };
                    _entities.Add(wfpr);
                    string strName = "Test";

                    HttpContextBase Context = ControllerContext.HttpContext;

                    //Checking the current context content
                    if (Context != null)
                    {

                        //Formatting the fully qualified website url/name
                        string appPath = string.Format("{0}://{1}{2}",
                                                    Context.Request.Url.Scheme,
                                                    Context.Request.Url.Host,
                                                    Context.Request.Url.Port == 80
                                                        ? string.Empty
                                                        : ":" + Context.Request.Url.Port);

                        string urlVerify = Url.Action("VerifyEmailResponse", new { id = strCode });
                        if (appPath.EndsWith("/") && urlVerify.StartsWith("/"))
                        {
                            appPath = appPath.Remove(appPath.Length - 1);
                        }

                        string u = String.Format("{0}{1}", appPath, urlVerify);

                        StringBuilder sbMessage = new StringBuilder();
                        sbMessage.AppendFormat("<p>Dear {0},</p>", strName);
                        sbMessage.AppendLine();
                        sbMessage.AppendLine();
                        sbMessage.AppendLine("<p>We have received a request to reset the password for your account. In order to change the password, please click the link below:</p>");
                        sbMessage.AppendLine();
                        sbMessage.AppendFormat("<p><a href=\"{0}\">{0}</a></p>", u);
                        sbMessage.AppendLine();
                        sbMessage.AppendLine();
                        sbMessage.AppendLine("<p>Thank you,</p>");
                        

                        System.Net.Mail.MailMessage netMail = new System.Net.Mail.MailMessage("test@test.net",
                                                                                              mu.Email,
                                                                                              "Reset Password",
                                                                                              sbMessage.ToString());

                        netMail.IsBodyHtml = true;
                        SmtpClient Sender = new SmtpClient();
                        Sender.EnableSsl = true;
                        Sender.Send(netMail);

                        //return RedirectToAction("VerifyEmailResponse", new { id = strCode });
                        return RedirectToAction("ResetPasswordEmailSent");
                    }
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("home", e);
                    Acs.Mail.SendErrorNotice(e.Message);
                }
            }
            return View();
        }
DotNet
  • 59
  • 4