Monday, April 2, 2012

Can Use the Code for using that Gmail Server on your .aspx.cs page

Suppose you have taken a Text Field name as   TextBox1 to accepting the Email ID. We need to search the email ID at our Customer table " tblcustomer " and will send the correspondence Password to the Email ID When Some one Click on the  " ForgetPwd " Button........

protected void ForgetPwdButton3_Click(object sender, EventArgs e)
{

string id = TextBox1.Text;
string sql = "select password from tblcustomer where customer_email='" + email+ "'";
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{

// GmailSender gs = new GmailSender();
string pwd = dr[0].ToString();
  if (SendMail("sender mail id", "sender pw", id, pwd))
{
Response.Write("<script language='javascript'>alert('Password has been sent to your email ID');</script>");
TextBox1.Text = "";
}
}
else
{
Response.Write("<script language='javascript'>alert('You have Entered wrong email ID');</script>");
}
}

NICE MAIL SERVER CODE for asp .net bt GMAIL SERVER...

This code you can use for Forget Password/ Mailing Form....Etc


public bool SendMail(string gMailAccount, string password, string to, string subject)
{
try
{
//Attachment mailAttachment = new Attachment(getfile);
NetworkCredential loginInfo = new NetworkCredential(gMailAccount, password);
MailMessage msg = new MailMessage();
msg.From = new MailAddress(gMailAccount);
msg.To.Add(new MailAddress(to));
msg.Subject = "Gifttoindia.co.in Password has been received";
msg.Body = "Your password is: " + subject;
msg.IsBodyHtml = true;
//msg.Attachments.Add(mailAttachment);
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = loginInfo;
client.Send(msg);

return true;
}
catch (Exception)
{
return false;
}

}