SmtpClient: A connection attempt failed because the connected party did not properly respond after a period of time

The following code works for me. Your code was giving me errors, I believe it was due to not setting the port to 587.

http://forums.asp.net/t/1250771.aspx/4/10

MailMessage mail = new MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtp.gmail.com",587);
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential(address, password);
smtp.Send(mail);

This happened to me due to my company security wifi. Once I changed to open wifi, the problem was solved automatically.

Leave a Comment