protected void subString()
        {            
            SqlConnection conSplit = new SqlConnection(ConfigurationManager.ConnectionStrings["connMSJ"].ConnectionString);
            SqlCommand cmdSplit = new SqlCommand("SELECT Password FROM Member WHERE (Username=@username AND Email=@email)", conSplit);
            cmdSplit.Parameters.AddWithValue("@username", txtUsername.Text);
            cmdSplit.Parameters.AddWithValue("@email", txtEmail.Text);
            conSplit.Open();
            SqlDataReader dtrSplit = cmdSplit.ExecuteReader();
            if (dtrSplit.Read())
                finalString = dtrSplit["Password"].ToString().Substring(0, 5);
            dtrSplit.Close();
            conSplit.Close();            
        }

        protected void sendResetPass()
        {
            MailMessage mailMessage = new MailMessage();
            mailMessage.To.Add(txtEmail.Text);
            mailMessage.From = new MailAddress("admin@MSJ.com");
            mailMessage.Subject = "Password Reset";
            mailMessage.Body = "New Password: " + finalString;
            SmtpClient smtpClient = new SmtpClient("smtp.your-isp.com");
            smtpClient.Send(mailMessage);
        }

        protected void ResetPassword(object sender, EventArgs e)
        {
            subString();
            if (finalString != null)
            {
                SqlConnection conReset = new SqlConnection(ConfigurationManager.ConnectionStrings["connMSJ"].ConnectionString);
                SqlCommand cmdReset = new SqlCommand("UPDATE Member SET Password=@password WHERE Username=@username", conReset);
                cmdReset.Parameters.AddWithValue("@username", txtUsername.Text);
                cmdReset.Parameters.AddWithValue("@password", finalString);
                conReset.Open();
                cmdReset.ExecuteNonQuery();
                conReset.Close();
                sendResetPass();
                Guest.Alert.Show("New Password has send to your E-mail/nplease do check your inbox");
                ReturnToHome(sender, e);
            }
            else
                Guest.Alert.Show("Invalid input: Username or E-mail have wrong input?");
        }

i was doing research through google. But i got the error send ResetPassword executed
(A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 216.69.186.201:25)
What's the problem? or do i miss something important?

Is the SMTP host you are trying to connect to listening on port 25?

Check their documentation for the correct settings.

How to check for the port setting?

Take a look at the SMTP Client Class on how to set properties like host, port, credentials, etc...

Code Behind
        protected void sendResetPass()
        {
            MailMessage mailMessage = new MailMessage();
            mailMessage.To.Add(txtEmail.Text);
            mailMessage.From = new MailAddress("admin@MSJ.com");
            mailMessage.Subject = "Password Reset";
            mailMessage.Body = "New Password: " + finalString;
            SmtpClient smtpClient = new SmtpClient("mail.your-isp.com");
            smtpClient.Send(mailMessage);
        }
Web.Config
  <system.net>
    <mailSettings>
      <smtp>
        <!--<network host="smtp.gmail.com" port="587" userName="admin@MSJ.com" password="adminMSJ" />-->
        <network host="smtp.live.com" port="25" userName="admin@MSJ.com" password="adminMSJ"/>
      </smtp>
    </mailSettings>    
  </system.net>

the problem are still the same. How to solve?
By the way, i want ask if my host is live mean indicate hotmail while the gmail indicate gmail right? can i do something like involve all, which mean is doesn't matter is gmail or hotmail.

I havent tried using gmail as an smtp provider for an asp.net application, but there is quite a bit of code examples online. Many people are configuring their code to use port 587 and to enable SSL. You may want to see if Google has documentation on which exact settings to use.

can i do something like involve all, which mean is doesn't matter is gmail or hotmail.

Yes, you can set up your own SMTP server to relay mail. However, you need to know what you are doing because you can easily be hacked and blacklisted if people send spam through your server. If you have your own smtp system, you send mail to it directly from your program and let the SMTP server use DNS to find other smtp servers (via MX records in DNS) or send mail directly to an ISP mail server via smarthosts setting.

host="smtp.gmail.com" is it means MY email is belongs to gmail or receiver?
i had tried many way, but still get the same errors, after that i found i didn't configure the network setting, thus i go set and it still remain unchange error occur. :/

host means the SMTP server you are sending mail to, not your receipient. Most SMTP server will accept your mail on port 25. However, some ISPs will not allow you to send mail on port 25 unless you are sending to them directly. They do this to prevent spammers on consumer based accounts.

So, if you are trying to use Google's mail server to relay mail, you need to check their documentation. Check with your ISP, they may allow you to relay mail from their servers.

If you have a hosting account (web), those providers also generally give you access to an SMTP server so that you can send mail from your web applications.

        protected void sendResetPass()
        {
            MailMessage mailMessage = new MailMessage("adminMSJ@gmail.com", txtEmail.Text);
            mailMessage.Subject = "Password Reset";
            mailMessage.Body = "New Password: " + finalString;
            mailMessage.IsBodyHtml = true;
            SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
            smtpClient.Credentials = new NetworkCredential()
            {
                UserName = "MSJDomain@gmail.com",
                Password = "Test"
            };
            smtpClient.EnableSsl = true;
            smtpClient.Send(mailMessage);
        }

After i watch a indian guy tutorial from youtube, i solve the port problem. if i change the port to gmail port is work fine. i also dont know why. :/
but another new problem occur

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

Its a generic message that deals with the fact that your client was not able to complete the authenticaiton process.

Either you have the wrong credentials or SSL is required for the connection.

the credential of username and password i though is declartion?

Ok, I did some research and Google requires that you allow access to the account before you can use it for SMTP services.

I tested your code, got the same error.

Then followed the instructions here and resolved the problem:
https://support.google.com/mail/answer/1173270?hl=el

YOu would do this for the account that you are using to authenticate to Google (gmail smtp service).

what should i put the username?
why are they so many example of outsite not doing this way? @@
they seem like doing some easier without the setting?

what should i put the username?

the username and password you are providing is the account that will authenticate on the SMTP service. If you do not want to authenticate, use an SMTP server that doesnt require authentication. Maybe use your ISP's SMTP server instead. Many SMTP providers are becoming more strict with regard to relaying to combat spammers. Its good practice to force authentication when providing SMTP relaying services.

why are they so many example of outsite not doing this way?

I dont know. For my hosted websites, I use my hosting provider's smtp server. They allow me to relay mail via port 25 without any authentication. They can do this because the source is coming from one of their web servers so if I decide to spam people, they can easily cut me off.

they seem like doing some easier without the setting?

Its possible that Google allowed it before (maybe this is relatively new) without this setting, but when I tried, I got the same error message you did. Upon doing some additional research, I found that I had to authorize it in my account. After I did the authorization for my web app, it worked without an issue.

okay. now i am able to send the email already, but can i change the display name? like i want display Admin XXX instead of displaying email address?
and after i send the email, i am not able to show the pop up message box. :/

sendResetPass();
                Guest.Alert.Show("New Password has send to your E-mail. Please do check your inbox");
                Response.Redirect("~/Guest.aspx");

Instead of MailMessage("adminMSJ@gmail.com", txtEmail.Text);, try the To and From properties.

Try mailMessage.From = "\"Gahhon\" <me@myDomain.com>"

mailMessage.To=" "

I'm not familiar with guest.alert.show.

You don't see anything because of the response.redirect.

Guest.Alert.Show("Content"); is a method from the Guest.aspx.cs which is public that showing a pop up message box. Is a javascript. What should i do able to show the message box at first before response.redirect?

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "RedirectToMainPage", string.Format("location.href = '{0}';", ResolveUrl("~/Guest.aspx")), true);

Problem solved. Thanks Jorge

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.