Elofsalbula
New Member
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).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.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.I simplified the code below for demonstration:\[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("[email protected]", "password") };var msg = new MailMessage("[email protected]", "[email protected]", "Any subject", "Any body"); smtp.Send(msg); // stuck heresmtp.Dispose(); // never reachedmsg.Dispose();\[/code\]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.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.Thank you,