title: Operation timeout error while sending mail through asp.net using gmail smtp
body: <p>I am using the code below .. and after submitting the form i m getting the following error :   </p>
  
  <blockquote>
    <p>Error:System.Net.Mail.SmtpException: The operation has timed out. at
    System.Net.Mail.SmtpClient.Send(MailMessage message) at
    Consultancy.Registration.Button1_Click1(Object sender, EventArgs e) in
    G:\servetechsolutions\Consultancy\Registration.aspx.cs:line 48Your</p>
  </blockquote>
  
  <p>code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Net;
  using System.Net.Mail;
  using System.Net.Security;
  
  namespace Consultancy
  {
      public partial class Registration : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
  
          }
  
  
          protected void Button1_Click1(object sender, EventArgs e)
          {
              try
              {
                  MailMessage mailMsg = new MailMessage();
  
                  mailMsg.From = new MailAddress(TextBox4.Text);
  
                  mailMsg.To.Add("ssumishra@gmail.com");
  
                  mailMsg.IsBodyHtml = true;
  
                  mailMsg.Subject = "Contact Details";
  
                  mailMsg.Body = "akjmsjfh";
  
  
                  SmtpClient smtp = new SmtpClient("smtp.gmail.com");
                  smtp.Port = 465;
                  //mailMsg.Priority = MailPriority.Normal;
  
                  smtp.Credentials = new System.Net.NetworkCredential("username@gmail.com", "password");
  
                  smtp.Timeout = 25000;
  
                  smtp.EnableSsl = true;
  
                  smtp.Send(mailMsg);
  
                  lblResult.Text = "Thank you. Your contact details and feed back has been submitted.";
              }
              catch (Exception ex)
              {
                  Response.Write("Error:" + ex.ToString());
              }
  
          }
  
  
  
  
  
          public bool True { get; set; }
      }
  }
  </code></pre>