Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

While working with Email sending in C#.NET in visual studio 2008 i got the below 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 has failed to respond 74.125.53.108:25

But the same code was working fine in some other PC but when i am testing today it gives me error in Send() method... Also my network connection is good where i am testing the email code..

Below is my email code

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.Host = "smtp.gmail.com"; smtp.Credentials = new System.Net.NetworkCredential("[email protected]",                                                             "MyPassword"); smtp.EnableSsl = true; smtp.Send(mail); 

What could be the reasons for such error..???

like image 239
DShah Avatar asked Aug 18 '11 05:08

DShah


People also ask

How do I fix SMTP failed to connect to server?

Change the server's SMTP restrictions. Then, add the specified website user to the list of users who are authorized to initiate outbound SMTP connections. Edit PHPMailer's configuration settings, such as host and port. Correct DNS resolution for the mail server.

How do I set up SMTP host?

From the Authentication Method list, select the method to authenticate the SMTP client to the SMTP server. In the Account Name field, enter the account or user name of the SMTP client to authenticate on the SMTP server. Generally, the account takes the name @ domain .com form.


1 Answers

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); 
like image 128
mutek Avatar answered Sep 23 '22 00:09

mutek