title: SmtpClient hangs with no exception thrown if wrong port was specified
body: <p>I was trying to send emails in my Asp.Net C# application using port 465 with host "smtp.gmail.com" but the whole application hangs (keeps loading). When debugging it's stuck at SmtpClient.Send(msg).</p>
  
  <p>Regardless of the credentials specified, it doesn't throw any exceptions to catch or any timeout errors. I have to close or refresh the page to regain access to the page.</p>
  
  <p>If I put port 587 instead then every thing works fine and the SmtpClient.Send responds and sends the email or returns a proper exception such as operation timeout or failure sending email based on the credentials.</p>
  
  <p>I simplified the code below for demonstration:</p>
  
  <pre><code>var smtp = new SmtpClient
                          {
                              Host = "smtp.gmail.com",
                              Port = 465,
                              EnableSsl = true,
                              Timeout = 200, // or any value it doesn't solve the problem
                              DeliveryMethod = SmtpDeliveryMethod.Network,
                              UseDefaultCredentials = false,
                              Credentials = new NetworkCredential("name@gmail.com", "password")
                          };
  
  var msg = new MailMessage("name@gmail.com", "name@gmail.com", "Any subject", "Any body"); 
  smtp.Send(msg); // stuck here
  smtp.Dispose(); // never reached
  msg.Dispose();
  </code></pre>
  
  <p>I tried SendAsync and reduced the timeout interval but this did not solve the problem. I think the problem is that smtp.gmail.com was reached but did not respond properly to port 465 and that's why the method was stuck.</p>
  
  <p>I need to avoid such behavior since my application allows dynamic settings of the smtp server details and I don't want the whole application to hang in case of wrong details were entered.</p>
  
  <p>Thank you,</p>
  
  <p><img src="https://i.stack.imgur.com/lV55I.png" alt="enter image description here"></p>