New Developer
New Developer

Reputation: 3305

Error when sending Email

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("[email protected]", "XXXX"),
        EnableSsl = true
    };

    client.Send("[email protected]", "[email protected]", "test", "testbody");
    Console.WriteLine("Sent");
    Console.ReadLine();
}
catch
{ }

Upvotes: 2

Views: 1837

Answers (2)

BLoB
BLoB

Reputation: 9725

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>

Upvotes: 1

Jake1164
Jake1164

Reputation: 12349

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.

Upvotes: 1

Related Questions