using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System; using System.Data; using System.Data.SqlClient; using System.Net.Mail; using System.Configuration; 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(); string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); SqlCommand cmd = new SqlCommand("SELECT UserName, Password FROM Users 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(); msg.From = new MailAddress(txtEmail.Text); msg.To.Add(txtEmail.Text); msg.Subject="Share It: Password Recovery"; msg.Body="Hi, " + ds.Tables[0].Rows[0]["FirstName"] +" " + ds.Tables[0].Rows[0]["LastName"] +"<br />As requested, here is your login details<br /><br />Your Username: " + ds.Tables[0].Rows[0]["UserName"] + "<br /><br />Your Password: " + ds.Tables[0].Rows[0]["Password"] + "<br /><br />Thank you for trusting us! Hope to hear from you soon!<br /><br />"; msg.IsBodyHtml = true; SmtpClient smtp = new SmtpClient("smtp.gamil.com", 587); smtp.UseDefaultCredentials = false; //smtp.Host = "smtp.gmail.com"; //smtp.Port = 587; smtp.Credentials = new System.Net.NetworkCredential("theresakang93@gmail.com", "passwordremoved"); smtp.EnableSsl = true; smtp.Send(msg); lbltxt.Text = "Your Password Details Sent to your mail."; } else lbltxt.Text = "The Email you entered does not exists."; } catch (Exception ex) { Console.WriteLine("{0} Exception caught.", ex); lbltxt.Text = "Unable to send"; }
Exception
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)