2

Please Do not mark this as duplicate. I can find so may questions related to this, however, none have helped me. Following is what I use for sending email in my c# application, but I get an exception saying:

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.129.108:587

My code is:

try {
    var client = new SmtpClient("smtp.gmail.com", 587) {
        Credentials = new NetworkCredential("XXXX@gmail.com", "XXXX"),
        EnableSsl = true
    };

    client.Send("XXXX@gmail.com", "XXXX@gmail.com", "test", "testbody");
    Console.WriteLine("Sent");
    Console.ReadLine();
}
catch
{ }
Jake1164
  • 12,291
  • 6
  • 47
  • 64
New Developer
  • 3,245
  • 10
  • 41
  • 78

2 Answers2

1

Check your port is correct, it should be Port 465 (with SSL) and Port 587 (with TLS).

If that doesn't work try port 25 with SSL

EDIT:

Is there a proxy server in the way? Try putting the following in your web.config

<system.net>
    <defaultProxy>
        <proxy usesystemdefault = "false"
               proxyaddress="http://address:port"
               bypassonlocal="false" />
    </defaultProxy>
</system.net>
Paul Zahra
  • 9,522
  • 8
  • 54
  • 76
1

Check that the port is not blocked by your firewall and especially not blocked by your corporate firewall.

There are many port scanners available depending on your needs, here is one suggestion to get you started.

Community
  • 1
  • 1
Jake1164
  • 12,291
  • 6
  • 47
  • 64
  • my firewall is already turned off. How to check my corporate firewall blocking me. I can access the gmail from my browser without any issue – New Developer Jun 27 '13 at 10:59
  • Accessing gmail via the browser uses standard ports, SMTP ports are not touched by the browser (the gmail server somewhere handles it all). – Jake1164 Jun 27 '13 at 11:02
  • Thanks for the answer. Actually the error was due to the port blocking on corporate firewall. Thanks again. Because I have never thought of that. – New Developer Jun 29 '13 at 19:53