winforms - C# Windows Form Application - Send email using gmail smtp -


I am trying to create a small program to send emails through smtp.gmail.com, but this Always indicates to me that "the operation timed out" I know that many solutions are available on the net but none of this works.

  try {MailMessage message = new MailMessage (); SmtpClient smtp = new SmtpClient (); message. From = new mail address ("from@gmail.com"); message. To Add (new mail address ("to@gmail.com")); Message.Subject = "test"; message. Body = "content"; Smtp.Port = 465; Smtp.host = "smtp.gmail.com"; Smtp.EnableSsl = true; Smtp.UseDefaultCredentials = false; Smtp.Credentials = New network credentials ("from@gmail.com", "pwd"); Smtp.DeliveryMethod = SmtpDeliveryMethod.Network; Smtp.Send (message); } Hold (Exception Pre) {MessageBox.Show ("err:" + ex.Message); }   

Is there a way to fix this?

Change port 587:

  {mail message message = New mail form (); SmtpClient smtp = new SmtpClient (); message. From = new mail address ("from@gmail.com"); message. To Add (new mail address ("to@gmail.com")); Message.Subject = "test"; message. Body = "content"; Smtp.Port = 587; Smtp.host = "smtp.gmail.com"; Smtp.EnableSsl = true; Smtp.UseDefaultCredentials = false; Smtp.Credentials = New network credentials ("from@gmail.com", "pwd"); Smtp.DeliveryMethod = SmtpDeliveryMethod.Network; Smtp.Send (message); } Hold (Exception Pre) {MessageBox.Show ("err:" + ex.Message); }    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -