Click here to Skip to main content
15,902,832 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this error occured
The remote name could not be resolved: 'smtp.gmail.com'
pls help me

What I have tried:

protected void Button_Click(object sender, EventArgs e) 
{
string username = string.Empty;
            string password = string.Empty;
            string constr = ConfigurationManager.ConnectionStrings["GlobalConnection"].ConnectionString;
            using (SqlConnection con = new SqlConnection(constr))
            {
                using (SqlCommand cmd = new SqlCommand("SELECT UserName,Password FROM Login_Mst WHERE EmailID = @EmailID"))
                {
                    cmd.Parameters.AddWithValue("@EmailID", txtemail.Text.Trim());
                    cmd.Connection = con;
                    con.Open();
                    using (SqlDataReader sdr = cmd.ExecuteReader())
                    {
                        if (sdr.Read())
                        {
                            username = sdr["UserName"].ToString();
                            password = sdr["Password"].ToString();
                        }
                    }
                    con.Close();
                }
            }
            if (!string.IsNullOrEmpty(password))
            {
                MailMessage mm = new MailMessage("ramdasshinde092@gmail.com", txtemail.Text.Trim());
                mm.Subject = "Password Recovery";
                mm.Body = string.Format("Hi {0},<br><br>Your password is {1}.<br><br>Thank You.", username, password);
                mm.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com";
                smtp.EnableSsl = true;
                NetworkCredential NetworkCred = new NetworkCredential();
                NetworkCred.UserName = "email@gmail.com";
                NetworkCred.Password = "password";
                smtp.UseDefaultCredentials = true;
                smtp.Credentials = NetworkCred;
                smtp.Port = 587;
                smtp.Send(mm);
                Label2.ForeColor = Color.Green;
                Label2.Text = "Password has been sent to your email address.";
            }
            else
            {
                Label2.ForeColor = Color.Red;
                Label2.Text = "This email address does not match our records.";
            }
        }
Posted
Updated 29-Jun-18 1:07am
v2
Comments
Richard MacCutchan 29-Jun-18 7:12am    
You are sending someone's password in clear text; such a bad idea. And it also looks like you are storing it in clear text in your database, an even worse idea.
Richard Deeming 29-Jun-18 10:02am    
NEVER store or send passwords in plain text:
Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

If the user forgets their password, don't send it to them. Instead, reset it:
Troy Hunt: Everything you ever wanted to know about building a secure password reset feature[^]

1 solution

Try setting the port number:
C#
smtp.Port = 587;
 
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