0

I am trying to send Email through my C# code but I am getting SmtpException

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 173.194.67.109:587

Here is how I am sending Email:

string HostAddress = "smtp.gmail.com";
MailMessage msg = new MailMessage();
msg.From = new MailAddress(fromEmail);
msg.Subject = "Test Email";
msg.Body = "Hi testing invoice";
msg.IsBodyHtml = true;
msg.To.Add(new MailAddress("ramshaafaq2012@gmail.com"));
SmtpClient client = new SmtpClient();
client.Host = HostAddress;
client.EnableSsl = true;
NetworkCredential creadit = new NetworkCredential();
creadit.UserName = msg.From.Address;
creadit.Password = Password;
client.UseDefaultCredentials = true;
client.Credentials = creadit;
client.Port = 587;
client.Send(msg);

A friend suggested to make some some changes in the Web.config file as Maybe a firewall is blocking the request. What changes should I make to resolve this issue?

Nuke
  • 1,039
  • 5
  • 13
  • 29
  • It hardly depends on your local configuration. You could try to connect via telenet to smtp.gmail.com on port 587 to determine if at least you can reach the remote host. If you can not, then you need to find wht's blocking you in your internal network – Oscar Jun 26 '15 at 09:53
  • is your firewall blocking any ports? can you log into the account from the computer the application is running on to make sure it hasn't been blacklisted? have you configured gmail to allow less secure applications? – user1666620 Jun 26 '15 at 09:55
  • why did you ask the same question a second time? https://stackoverflow.com/questions/31067990/smtpexception-while-sending-email i'm voting to close this. – user1666620 Jun 26 '15 at 09:57
  • you need to logged in the google server then only possible. – Jagadeesh Govindaraj Jun 26 '15 at 09:59
  • this has been answered many times in SO! check [this](http://stackoverflow.com/q/32260/17447) and [this](http://stackoverflow.com/q/704636/17447). And please do some research before posting – naveen Jun 26 '15 at 10:10
  • tried `client.DeliveryMethod = SmtpDeliveryMethod.Network` and `client.Credentials = new NetworkCredential(fromEmail, Password)`? – naveen Jun 26 '15 at 10:12
  • Thank you.Of all the solutions given on these links Nothing worked except that `Turn On Access For Less Secure Apps` setting of the Gmail account :) – Nuke Jun 28 '15 at 21:21

0 Answers0