title: Unable to send mail over smtp server, as the 'operation timeout' error occurs
body: <p>Unable to send mail over smtp server, as the 'operation timeout' error occurs. I have tried almost all the methods given on this website, have tried using another port number and also the client other than gmail, I wonder what the problem is. Following is the attached code segment.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Net.Security;
  using System.Net.Mail;
  using System.Net;
  
  public partial class home : System.Web.UI.Page
  {
      SmtpClient smtp = new SmtpClient();
  
      MailMessage newMail = new MailMessage();
  
      protected void Page_Load(object sender, EventArgs e)
      {   
          smtp.Host = "smtp.gmail.com";
          smtp.Port = 465;
          smtp.Credentials = new NetworkCredential("user@gmail.com", "password");
          smtp.UseDefaultCredentials = false;
          smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
          smtp.EnableSsl = true;
  
          newMail.From = new MailAddress("user@gmail.com");
          newMail.Priority = MailPriority.High;
      }
      protected void Button_send_Click(object sender, EventArgs e)
      {
          try
          {
              newMail.To.Add(new MailAddress(TextBox_to.Text));
              newMail.Subject = TextBox_sub.Text;
              newMail.Body = TextBox_mail.Text;
              smtp.Send(newMail);
              Label_msg.Text = "Message Sent Successfully.";
              Label_msg.Visible = true;
          }
          catch (Exception ex)
          {
              Label_msg.Text = "Message not sent &lt;br/&gt;" + ex.Message;
          }
      }
  }
  </code></pre>