首页 > 代码库 > 找回密码,发送原密码到注册邮箱!
找回密码,发送原密码到注册邮箱!
1 #region //发送邮件方法 支持带附件 2 /// <summary> 3 /// 发送edm邮件,可以附加附件 4 /// </summary> 5 /// <param name="StrTo">收件人地址</param> 6 /// <param name="strFrom">发件人地址</param> 7 /// <param name="StrBody">邮件内容</param> 8 /// <param name="strSubject">邮件主题</param> 9 /// <param name="name">发件人地址</param> 10 /// <param name="pwd">发件人密码</param> 11 /// <returns>返回是否发送成功</returns> 12 public static bool SendEDMEmailBy47Server(string StrTo, string strFrom, string StrBody, string strSubject, string name, string pwd) 13 { 14 string sHos = string.Empty;//根据发送邮箱地址获取你的smtp主机 15 if (name.Contains("@163")) 16 { 17 sHos = "smtp.163.com"; 18 } 19 else if (name.Contains("@126")) 20 { 21 sHos = "smtp.126.com"; 22 } 23 else if (name.Contains("@qq")) 24 { 25 sHos = "smtp.qq.com"; 26 } 27 else if (name.Contains("@sohu")) 28 { 29 sHos = "smtp.sohu.com"; 30 } 31 else if (name.Contains("@sina")) 32 { 33 sHos = "smtp.sina.com"; 34 } 35 else if (name.Contains("@tom")) 36 { 37 sHos = "smtp.tom.com.cn"; 38 } 39 else if (name.Contains("@foxmail")) 40 { 41 sHos = "smtp.foxmail.com"; 42 } 43 else if (name.Contains("@139")) 44 { 45 sHos = "smtp.139.com"; 46 } 47 48 System.Net.Mail.MailAddress fromEmail = new System.Net.Mail.MailAddress(strFrom);//发件人的地址 49 System.Net.Mail.MailAddress toEmail = new System.Net.Mail.MailAddress(StrTo);//收件人地址 50 System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(fromEmail, toEmail); 51 52 mail.Body = StrBody; 53 mail.Subject = strSubject; 54 mail.IsBodyHtml = true; 55 mail.BodyEncoding = System.Text.Encoding.UTF8; 56 mail.Priority = System.Net.Mail.MailPriority.Normal; 57 58 System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(); 59 smtpClient.Host = sHos;//这里设置成你的smtp主机名或者ip地址 60 smtpClient.Port = 25; 61 smtpClient.UseDefaultCredentials = false; 62 smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; 63 smtpClient.Credentials = new System.Net.NetworkCredential(name, pwd);//你的用户名和密码 64 //以下是邮件附件部分,path一般是从FileUpload控件中取~ 65 try 66 { 67 smtpClient.Send(mail); 68 } 69 catch (Exception e) 70 { 71 Console.WriteLine(e.Message); 72 return false; 73 } 74 return true; 75 } 76 #endregion 77 /// <summary> 78 /// 用户根据账号找回密码 79 /// </summary> 80 /// <param name="sender"></param> 81 /// <param name="e"></param> 82 protected void link_btn_mima_Click(object sender, EventArgs e) 83 { 84 if (txt_login_account.Text == "" || txt_login_account.Text == null) 85 { 86 //Response.Write("<script>alert(‘请输入用户名‘)</script>"); 87 lbl_error_show.Text = "请输入用户名"; 88 } 89 else 90 { 91 user = bum.getUserModel(txt_login_account.Text); 92 if (user.User_qq == "" || user.User_qq == null) 93 { 94 //Response.Write("<script>alert(‘对不起您没有完善个人信息,无法找回密码!‘)</script>"); 95 lbl_error_show.Text = "对不起您没有完善个人信息,无法找回密码!"; 96 } 97 else 98 { 99 100 string StrTo = user.User_qq.ToString() + "@qq.com";101 string strFrom = "527553566@qq.com";102 string StrBody = "您在B2BTYLY中注册账号:" + user.User_name + "所对应的密码是:" + user.User_pwd + "。";103 string strSubject = "B2BTYLY网站找回密码提示!";104 string name = "527553566@qq.com";//这是发送邮件的账号105 string pwd = "************";//这是你的QQ密码106 bool bResult = SendEDMEmailBy47Server(StrTo, strFrom, StrBody, strSubject, name, pwd);107 if (bResult)108 {109 lbl_error_show.Text = "发送成功!";110 }111 else112 {113 lbl_error_show.Text = "服务器忙,请稍候再试!";114 }115 }116 }117 }118
以上是我实现的过程这个是在我的一个项目中用到的,没有专门去写demo,仅供学习参考和知识记录
有问题请联系QQ527553566
找回密码,发送原密码到注册邮箱!
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。