I got the solution as follows:
SqlConnection conn = new SqlConnection(@"Data Source=COMP06\MSSQLSERVER2008R;Initial Catalog=EmployeeData;User ID=sa;Password=logical");
conn.Open();
SqlCommand cmd = new SqlCommand("select * from Register where EmailId='"+EmailIdText.Value+"'", conn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
string Name = dr["FirstName"].ToString();
string psw = dr["Password"].ToString();
string UId = dr["UserId"].ToString();
MailMessage msg = new MailMessage();
msg.From = new MailAddress("myemailid@gmail.com");
msg.To.Add(new MailAddress(EmailIdText.Value));
msg.Subject = "Your Password is:";
msg.IsBodyHtml = true;
msg.Body ="<br><b>Hello,"+Name+"<br><br><b>Your User Id is: "+UId+
"<br><br><b>Your Password is </b>" + psw +
"<br><br><b>Name: </b>" + EmailIdText.Value;
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.Credentials = new System.Net.NetworkCredential("myemailid@gmail.com", "mypassword");
smtp.EnableSsl = true;
smtp.Send(msg);
Label1.Text = "Your password is sent to your EmailId....!!";
dr.Close();
conn.Close();
}
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}