找回密码

一.填写相关的信息

  1.展示页面用户填写信息(用户名,邮箱)

  2.发送邮件到用户的邮箱(构造符合要求的链接)

  3.用户打开邮箱(点击链接跳转修改密码页面)

 

 1         #region 发送电子邮件
 2         /// <summary> 
 3         /// 发送电子邮件 
 4         /// </summary> 
 5         /// <param name="MessageFrom">发件人邮箱地址</param> 
 6         /// <param name="MessageTo">收件人邮箱地址</param> 
 7         /// <param name="MessageSubject">邮件主题</param> 
 8         /// <param name="MessageBody">邮件内容</param> 
 9         /// <returns></returns> 
10         public static bool Send(MailAddress MessageFrom, string MessageTo, string MessageSubject, string MessageBody)
11         {
12             MailMessage message = new MailMessage();//两个类,别混了,要引入System.Net这个Assembly
13 
14             message.From = MessageFrom;
15             message.To.Add(new MailAddress(MessageTo)); //收件人邮箱地址可以是多个以实现群发 
16             message.Subject = MessageSubject;
17             message.Body = MessageBody;
18             message.IsBodyHtml = true; //是否为html格式 
19             message.Priority = MailPriority.High; //发送邮件的优先等级 
20             SmtpClient sc = new SmtpClient();
21             sc.Host = "smtp.163.com"; //smtp.163.com,smtp.qq.com,指定发件人使用的SMTP服务器。
22             sc.Port = 25; //指定发送邮件端口 
23             sc.Credentials = new System.Net.NetworkCredential("XXX", "XXX"); //指定登录服务器的用户名(邮箱)和密码(发件人的邮箱登陆密码) 
24             try
25             {
26                 sc.Send(message); //发送邮件 
27                 return true;
28             }
29             catch
30             {
31 
32                 return false;
33 
34 
35             }
36 
37         }
38 
39         #endregion
 1   #region 获取发送数据
 2         /// <summary>
 3         /// 获取发送数据 
 4         /// </summary>
 5         /// <param name="UserName"> 帐号</param>
 6         /// <param name="Eamil">邮箱</param>
 7         public static void sendmail(string UserName, string Eamil, string pwd)
 8         {
 9 
10             string rand = pwd;
11             string key = rand + UserName + Eamil + "Base";
12             System.Net.Mail.MailAddress MessageFrom = new System.Net.Mail.MailAddress("15818928492@163.com"); //发件人邮箱地址 ,与方法里面的发送账号必须一致
13             if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Eamil))
14             {
15                 //发送邮件
16                 StringBuilder sb = new StringBuilder();
17                 sb.Append("亲爱的【" + UserName + "】!<br/>您好:<br/>");
18                 sb.Append("您使用了邮箱找回密码功能,您的激活码是:" + rand + "<br/><br/>");
19                 //sb.Append("点击以下链接设置新密码。<br/><br/>");
20                 //sb.Append("<a href =\"http://www.xxxx.com/findpwd.aspx?id=" + key + "\">http://localhost:1317/admin/FindPwd/Stepthree?id=" + key + " </a><br/><br/>");
21                 //sb.Append("(如果无法点击该URL链接地址,请将它复制并粘帖到浏览器的地址输入框,然后单击回车即可。)<br/><br/>");
22                 sb.Append("注意:该激活码只限一次使用,否则该链接将会失效。<br/><br/>");
23                 sb.Append("我们将一如既往、热忱的为您服务!<br/><br/>");
24                 string MessageBody = sb.ToString();
25                 Kits.Send(MessageFrom, Eamil, "xxxx--找回密码", MessageBody);
26 
27 
28 
29             }
30 
31         }
32         #endregion
 1  #region 找回密码
 2         public ActionResult Active()
 3         {
 4             int id;
 5             if (int.TryParse(Request["id"], out id))
 6             {
 7                 var model = bll.Eamil(c => c.Id == id).FirstOrDefault();//根据ID查询 数据库,或者数据
 8                 if (model.ActiveCode == Request["activeCode"])
 9                 {
10                     model.Actived = true;
11                     if (bll.UpdateEntity(model))
12                     {
13                         return Content("找回密码成功!!");
14                     }
15                     else
16                     {
17                         return Content("找回密码失败!!");
18                     }
19                 }
20                 else
21                 {
22                     return Content("参数错误");
23                 }
24             }
25             else
26             {
27                 return Content("用户编号错误!!");
28             }
29         }
30         #endregion

 

  

posted @ 2015-05-23 19:05  寒冷记忆  阅读(127)  评论(1)    收藏  举报