using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Net.Mail; using System.Data.SqlClient; public partial class Forgotpassword : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnSubmit_Click(object sender, EventArgs e) { try { DataSet ds = new DataSet(); using (SqlConnection con = new SqlConnection("Data Source=ARUN-PC\\SQL;Integrated Security=true;Initial Catalog=TEST")) { con.Open(); SqlCommand cmd = new SqlCommand("SELECT UserName,Password FROM User_Information Where Email= '" + txtEmail.Text.Trim() + "'", con); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(ds); con.Close(); } if (ds.Tables[0].Rows.Count > 0) { MailMessage Msg = new MailMessage(); // Sender e-mail address. Msg.From = new MailAddress(txtEmail.Text); // Recipient e-mail address. Msg.To.Add(txtEmail.Text); Msg.Subject = "Your Password Details"; Msg.Body = "Hi, <br />Please check your Login Detailss<br /><br />Your Username: " + ds.Tables[0].Rows[0]["UserName"] + "<br /><br />Your Password: " + ds.Tables[0].Rows[0]["Password"] + "<br /><br />"; Msg.IsBodyHtml = true; // your remote SMTP server IP. SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.Credentials = new System.Net.NetworkCredential("MyGMAIL@gmail.com", "MYPASSWORD"); smtp.EnableSsl = true; smtp.Send(Msg); //Msg = null; lbltxt.Text = "Your Password Details Sent to your mail"; // Clear the textbox valuess txtEmail.Text = ""; } else { lbltxt.Text = "The Email you entered not exists."; } } catch (Exception ex) { Console.WriteLine("{0} Exception caught.", ex); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)