Click here to Skip to main content
15,918,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection();
        con.ConnectionString = ConfigurationManager.ConnectionStrings["sampleConnectionString"].ToString();
        DataTable dt = new DataTable();
        con.fetch("select username,password from register where email='" + TextBox3.Text + "'", ref dt);
        DataTable dt = new DataTable();

        if (dt.Rows.Count == 0)
        {
            Response.Redirect("~/Default.aspx");
        }
        else
        {
            try
            {
                MailMessage mm = new MailMessage();
                SmtpClient smtp = new SmtpClient();
                mm.From = new MailAddress(TextBox3.Text);
                //mm.CC.Add("");
                mm.To.Add(new MailAddress("sankarreddyece@gmail.com"));
                mm.Subject = "this is password recovary email";
                mm.Body = "your  username is :-" + dt.Rows[0][0].ToString() + " and your password is:-" + dt.Rows[0][1].ToString() + "";
                mm.IsBodyHtml = true;
                smtp.Host = "smtp.gmail.com"; //You can add this in the webconfig
                smtp.EnableSsl = true;
                System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
                NetworkCred.UserName = "sankarreddyece@gmail.com ";
                NetworkCred.Password = "ksr@740640";
                smtp.UseDefaultCredentials = true;
                smtp.Credentials = NetworkCred;
                smtp.Port = 587; //this is Gmail port for e-mail
                smtp.Send(mm);//send an e-mail
                Response.Write("password sented");
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }



hi can use this code for sending forget password s.but it doesn't show any error.mail also not sented .can any body rectify this
Posted
Updated 1-Mar-12 21:37pm
v2
Comments
Anuja Pawar Indore 2-Mar-12 5:58am    
Why repost. Use improve question link and add your code there itself.

Sending a password via e-mail is a bad idea someone can spy on your communication and get the password.

Not everyone knows that there is a secure way to exchange secret information through absolutely open channels of communication and keep the messages in secret even from the one who was spying on the channel since before both participants were burn. So many people argues with me that this is impossible! They argued that if as soon as the two partners need to say "something special" to each other, the man in the middle can here it, too. Such considerations are based on a subtle logical flaw.

Nevertheless, such methods are widely known under the common name public-key cryptography:
http://en.wikipedia.org/wiki/Public-key_cryptography[^].

Follow the action taken by Alice and Bob to make sure was right.

Such algorithms are well available in .NET. Please see:
http://msdn.microsoft.com/en-us/library/system.security.cryptography.asymmetricalgorithm.aspx[^].

—SA
 
Share this answer
 
v2
try this,
MailAddress mailfrom = new MailAddress ( "frommail@gmail.com" );
MailAddress mailto = new MailAddress ( "tomail@gmail.com" );
MailMessage newmsg = new MailMessage ( mailfrom, mailto );

newmsg.Subject = "Subject of Email";
newmsg.Body = "Body(message) of email";

////For File Attachment, more file can also be attached

Attachment att = new Attachment ( "G:\\code.txt" );
newmsg.Attachments.Add ( att );

SmtpClient smtps = new SmtpClient ( "smtp.gmail.com", 587 );
smtps.UseDefaultCredentials = false;
smtps.Credentials = new NetworkCredential             ( "mail@gmail.com", "pwd" );
smtps.EnableSsl = true;
smtps.Send ( newmsg );
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900