Click here to Skip to main content
16,017,238 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a error when send email
C#
SqlConnection scon_forgott =
                           new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ToString());



                       scon_forgott.Open();
                       DataTable dt = new DataTable();
                       SqlDataAdapter da = new SqlDataAdapter("select * from tbl_Users where Email='" + a.Text + "'",
                           scon_forgott);

                       da.Fill(dt);

                       if (dt.Rows.Count > 0)
                       {
                           string newpass = Guid.NewGuid().ToString();
                           string hashPass = FormsAuthentication.HashPasswordForStoringInConfigFile(newpass, "MD5");
                           Classes.Users clsUsers = new Classes.Users();
                           DataSet ds = clsUsers.SelectRow_User(dt.Rows[0]["UserName"].ToString());
                           DataRow drRow = ds.Tables["tbl_Users"].Rows[0];
                           clsUsers.updatePasswordNew(int.Parse(drRow["ID"].ToString()), hashPass);
                           MailMessage mail = new MailMessage();
                           mail.From = new MailAddress("email@mydomains.com");
                           mail.To.Add(new MailAddress(drRow["Email"].ToString()));
                           mail.Subject = "subjectttttt";
                           mail.Body ="booooooooodddddyyyyyyyyy";
                           mail.IsBodyHtml = true;
                           SmtpClient smtp = new SmtpClient("smpt.mydomains.com");
                           smtp.Credentials = new NetworkCredential("email@mydomains.com", "bIXSg1a8");
                           smtp.EnableSsl = false;
                           smtp.Send(mail);
                           Label lbl = LoginView1.FindControl("lblError") as Label;
                           lbl.ForeColor = Color.ForestGreen;
                           lbl.Text ="send new pass";
                       }
                       else
                       {
                           Label lbl = LoginView1.FindControl("lblError") as Label;
                           lbl.ForeColor = Color.Red;
                           lbl.Text = "user not found";
                       }


and my error
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host ...
how to resolve it.
Posted
Comments
Kornfeld Eliyahu Peter 22-Jun-14 2:31am    
For some reason your code can not connect the SMTP server.
1. Your parameters are wrong. Check them!
2. There is a proxy server between you and the SMPT server...

The error seems to be related to your SMTP settings.Your SMTP server is not accessible - wrong IP address, username or password.

Also the port for SMTP client should be 25 (the default value) but you should check on your SMTP server about it.

You could also try to increase the value of smtp.Timeout to a higher value.
 
Share this answer
 
change EnableSsl to True, and you need the smtp.Port property..... what is the SMTP port???

such as: Gmail port is 587


C#
SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Credentials = new NetworkCredential("faaaadi.halboni585@gmail.com", "your Password");
//client.UseDefaultCredentials = False
client.Port = 587;
//client.Timeout = 20000
client.Send(msg);
 
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