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 74.125.45.25:587 – Connecting to Gmail with .NET


I’ve been trying to setup a web form to send mail using my google account, but I have repeatedly had no luck. I’ve found many posts about people who are having the same problems, but have yet to come across a viable solution. Here is the code, if you see something that is incorrect, please let me (and others) know how to fix it.

System.Net.Mail.MailMessage mail = new MailMessage();
mail.From = new MailAddress("no-reply@mydomain.com", "Do Not Reply");
mail.To.Add(new MailAddress("email@mydomain.com", "My Email"));
mail.Subject = "Email Subject";
mail.Body = message;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.EnableSsl = true;
client.Port = 587;
client.Host = "smtp.google.com";
client.UseDefaultCredentials = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new System.Net.NetworkCredential("no-reply@mydomain.com", "password");
client.Send(mail);

Leave a Reply

Your email address will not be published. Required fields are marked *