Add try / catch to the code, and everything is fine. This, in the worst case, ultimately means a timeout. It will not work forever, and Google will not keep communication open forever (in fact, SMTP is pretty implacable when it comes to timeouts ... if you're slow, it will kill the connection).
try { var client = new SmtpClient("smtp.gmail.com", 587) { Credentials = new NetworkCredential(fromAddr, pass), EnableSsl = true }; MailMessage mail = new MailMessage(fromAddr, toAddr, subject, body); mail.IsBodyHtml = true; client.Send(mail); } catch {
When it comes to testing ... use a different gMail account. You can also check your limit of sent letters per day. You donβt know what the gMail number is, but they do not just allow you to send how much more you want to send.
Clarence klopfstein
source share