protected void Send_Click(object sender, EventArgs e) { string username = string.Empty; string password = string.Empty; string email = txtEmail.Text.Trim(); RegisterUser objUser = new RegisterUser(); DataTable dt = objUser.GetNameUnameEmail(email); if (dt.Rows.Count > 0) { username = dt.Rows[0]["UserName"].ToString(); password = dt.Rows[0]["Password"].ToString(); } if (!string.IsNullOrEmpty(password)) { MailAddress from = new MailAddress("*****@*****.**", "Forgotten Password"); MailMessage mm = new MailMessage(from.ToString(), email); mm.Subject = "Password Recovery"; mm.Body = string.Format("Hi, {0}<br /><br />your password is <b><em>{1}<em></b>.<br /><br />Thank You.<br/><br/>This is an autogenerated email.Please do not reply back.", username, password); mm.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; NetworkCredential NetworkCred = new NetworkCredential(); NetworkCred.UserName = "******"; NetworkCred.Password = "******"; smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; smtp.Port = 587; smtp.Send(mm); ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "SuccessMessage", "CloseWindow(); window.parent.EmailSuccessNotification();", true); } else { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "ErrorMessage", "CloseWindow();window.parent.EmailErrorNotification();", true); } }