随笔 - 24, 文章 - 0, 评论 - 29, 阅读 - 58377
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

忘记密码发送邮件提醒的代码

Posted on   豆丁不想长大  阅读(466)  评论(0编辑  收藏  举报

 

 1 public partial class CustomersForgetPassWord : System.Web.UI.Page
 2 {
 3     //public TextBox UserBox;
 4     private string emailstring;
 5     private string forgetuser;
 6     private string forgetpass;
 7     public SqlConnection sqlconn;
 8     public SqlCommand sqlcomm;
 9     public SqlDataReader slqdtrdr;
10     static bool mailSent = false;
11 
12     protected void Page_Load(object sender, EventArgs e)
13     {
14 
15     }
16     protected void GetButton_Click(object sender, EventArgs e)
17     {
18         try
19         {
20             string strconn = ConfigurationSettings.AppSettings["scon"];
21             sqlconn = new SqlConnection(strconn);
22             sqlconn.Open();
23             string strsql = "select * from Customers where CustomerUserName='" + UserBox.Text + "'";
24             sqlcomm = new SqlCommand(strsql, sqlconn);
25             slqdtrdr = sqlcomm.ExecuteReader(CommandBehavior.CloseConnection);
26             if (slqdtrdr.Read())
27             {
28                 Session["CustomerID"]=slqdtrdr["CustomerID"].ToString();
29                 //emailstring = "zhaojing@etong2000.com";
30                 emailstring = String.Format("{0}", slqdtrdr[5]);
31                 forgetuser = String.Format("{0}", slqdtrdr[1]);
32                 //forgetpass = String.Format("{0}",slqdtrdr[5]);
33             }
34             else
35             {
36 
37             }
38         }
39         catch (Exception en)
40         {
41 
42         }
43         finally
44         {
45             slqdtrdr.Close();
46             slqdtrdr.Dispose();
47             sqlconn.Close();
48         }
49         //specify SMTP Server
50         string server = "mail.etong2000.com";
51         if (UserBox.Text != forgetuser)
52         {
53             Response.Write("<script>alert('Can not send to your email box!')</script>");
54         }
55         else
56         {
57             try
58             {
59                 forgetpass = DateTime.Now.Millisecond.ToString() + DateTime.Now.Second.ToString();
60                 //smtp server
61                 string strSmtpServer = "amidco.com";
62                 //username for sending
63                 //string strTo = "info@amidco.com,williamlroberts@gmail.com,gregdirst2@yahoo.com";
64                 //string strTo = "zhaojing@etong2000.com";
65                 //password for sending
66                 string strFromPass = "781106";
67                 //target of sending
68                 string strFrom = "qi.tong@amidco.com";
69                 //subject of sending
70                 string strSubject = "Foodservice Industry Network, LLC";
71                 //body of sending
72                 string strBody = "Foodservice Industry Network, LLC" + "\n" + "Forget Password." + "\n" + "User Name: " + forgetuser + " Your Temporary Password is: " + forgetpass + " Please Change it!";
73 
74                 System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer);
75                 client.UseDefaultCredentials = false;
76                 client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass);
77                 client.DeliveryMethod = SmtpDeliveryMethod.Network;
78 
79                 System.Net.Mail.MailMessage message = new MailMessage("info@foodserviceindustrynetwork.com", emailstring, strSubject, strBody);
80                 message.BodyEncoding = System.Text.Encoding.UTF8;
81                 message.IsBodyHtml = true;
82                 Response.Write("<script language='javascript'>window.alert('Your Temporary password has been sent to your email box.');window.location='./UserCode/CustomersChangePassword.aspx';</script>");
83                 client.Send(message);
84             }
85             catch (Exception ex)
86             {
87                 Response.Write("<script>alert('Can not send to your email box!')</script>");
88                 //Response.Write(ex.Message);
89             }
90         }
91     }
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示