using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Net;
using System.Net.Mail;
public partial class pwdsend : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=AAPTI-A20B83733\\SQLEXPRESS;Initial Catalog=NewLogin;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("SELECT username,password FROM loginsend Where mailid= '" + TextBox1.Text + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
if (ds.Tables[0].Rows.Count > 0)
{
MailMessage email = new MailMessage();
email.From = new MailAddress(TextBox1.Text);
email.To.Add(TextBox1.Text);
email.Subject = "Your Forrget Password:";
email.Body = "Hi,Your Username is: " + " " + ds.Tables[0].Rows[0]["username"] + "Your Password is: " + " " + ds.Tables[0].Rows[0]["password"] + "";
email.IsBodyHtml = true;
SmtpClient smtpc = new SmtpClient("smtp.gmail.com");
smtpc.Port = 587;
smtpc.Credentials = new System.Net.NetworkCredential("nagkumart@gmail.com", "123369987");
smtpc.EnableSsl = true;
smtpc.Send(email);
Label2.Visible = true;
Label2.Text = "Your password has been sent to your email address";
}
else
{
Label2.Text = "This email address is not exist in our Database try again";
}
}
}
No comments:
Post a Comment