忘记密码发送电子邮件给用户

编程入门 行业动态 更新时间:2024-10-27 05:31:49
本文介绍了忘记密码发送电子邮件给用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个表单,我将PasswordRecovery控件拖放到表单。当用户忘记密码时,如何设置控件以从与用户电子邮件匹配的数据库中发送密码?

I have a form that I drag and dropped the PasswordRecovery control to the form. When a user forgets their password, how can I setup the control to send the password from the database that matches the user email?

using System; using System.Data.SqlClient; using System.Configuration; using System.Data; using System.Net.Mail; public partial class ForgotPassword : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnPass_Click(object sender, EventArgs e) { //Create Connection String And SQL Statement string strConnection = ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString; string strSelect = "SELECT EmailAddress, Password FROM TableSecurity WHERE EmailAddress = @EmailAddress"; SqlConnection connection = new SqlConnection(strConnection); SqlCommand command = new SqlCommand(); command.Connection = connection; command.CommandType = CommandType.Text; command.CommandText = strSelect; SqlParameter email = new SqlParameter("@EmailAddress", SqlDbType.VarChar, 50); email.Value = TextBoxEA.Text.Trim().ToString(); command.Parameters.Add(email); //Create Dataset to store results and DataAdapter to fill Dataset DataSet dsPwd = new DataSet(); connection.Open(); SqlDataAdapter dAdapter = new SqlDataAdapter(command); dAdapter.Fill(dsPwd); connection.Close(); if (dsPwd.Tables[0].Rows.Count < 0) { MailMessage loginInfo = new MailMessage(); loginInfo.To.Add(TextBoxEA.Text.ToString()); loginInfo.From = new MailAddress("YourID@sasccoc"); loginInfo.Subject = "Forgot Password Information"; loginInfo.Body = "EmailAddress: " + dsPwd.Tables[0].Rows[0]["EmailAddress"] + "<br /><br />Password: " + dsPwd.Tables[0].Rows[0]["Password"] + "<br /><br />"; loginInfo.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "mail.sasccoc"; smtp.Port = 25; smtp.EnableSsl = true; smtp.Credentials = new System.Net.NetworkCredential("YourEmailID@sasccoc", "YourEmailPassword"); smtp.Send(loginInfo); lblMessage.Text = "Password is sent to you email id,you can now <a href='Login.aspx'>Login</a>"; try { smtp.Send(loginInfo); } catch (Exception ex) { lblMessage.Text = "Oops, Something Went Wrong When We Tried to Send The Email"; return; } } else { lblMessage.Text = "Email Address Not Registered"; } } }

推荐答案

首先检索电子邮件ID和密码您要向其发送密码的用户,然后 MailMessage newMail = new MailMessage(); newMail.To =mail我要向谁发送密码; newMail.Subject =主题; newMail.Body =密码和其他内容; SmtpClient SmtpSender =新的SmtpClient(); SmtpSender.Port = 25; SmtpSender.Host =mail.YOURDOMAIN; SmtpSender.Send(newMail); 试试这个 First retrive the email id and password of user to whom you want to send password, and then MailMessage newMail = new MailMessage(); newMail.To="mail Id to whom you want to send password"; newMail.Subject="Subject"; newMail.Body="Password and other content "; SmtpClient SmtpSender = new SmtpClient(); SmtpSender.Port = 25; SmtpSender.Host = "mail.YOURDOMAIN"; SmtpSender.Send(newMail); try this

更多推荐

忘记密码发送电子邮件给用户

本文发布于:2023-05-31 22:07:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/400267.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:忘记密码   发送电子邮件   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!