/// <summary> /// 发送邮件成功 /// </summary> /// <param name="username"></param> /// <returns></returns> public ActionResult SendMailComplete(string username = "") { if (Session["ValidEmail"] == null || string.IsNullOrEmpty(Session["ValidEmail"].ToString())) { TempData["info"] = "验证码过期,请重新找回"; return(RedirectToAction("ForgotPwd", "User")); } ViewBag.Email = Session["ValidEmail"].ToString(); var timenow = DateTime.Now; var relative = Url.Action("ChangePassword", "User", new { name = Encrypt.EncryptString(username), active = Encrypt.EncryptString(DateTime.Now.ToString(CultureInfo.InvariantCulture)) }); if (Request.Url != null) { var url = Request.Url.OriginalString.Replace(Request.Url.PathAndQuery, "") + relative; var alink = string.Format("<a href='{0}'>{0}</a>", url); var content = string.Format("亲爱的用户 {0}: 您好!<br /> <br />您收到这封这封电子邮件是因为您 (也可能是某人冒充您的名义) 申请了一个新的密码。假如这不是您本人所申请, 请不用理会这封电子邮件, 但是如果您持续收到这类的信件骚扰, 请您尽快联络管理员。" + "<br /> 要使用新密码,请使用以下链接启用密码。<br />{1}(如果无法点击该URL链接地址,请将它复制并粘帖到浏览器的地址输入框,然后单击回车即可。该链接使用后将立即失效。)<br />" + "注意:请您在收到邮件1个小时内({2}前)使用,否则该链接将会失效。<br /><br />", username, alink, timenow.AddHours(1)); //send mail; try { var res = _portalContext.SendMail(Session["ValidEmail"].ToString(), content, "找回密码"); if (!res) { TempData["error"] = "邮件发送失败,请确认邮箱是否正确"; } else { // AddFindPasswordLog(user.Id, user.UserName); } } catch (Exception e) { TempData["error"] = "邮件发送失败" + e.Message; } } return(View()); }