title: smtp exception Failure sending mail?
body: <pre><code>StringBuilder emailMessage = new StringBuilder();
  emailMessage.Append("Dear Payment Team ,");
  emailMessage.Append("&lt;br&gt;&lt;br&gt;Please find the Payment instruction");    
  
  try
  {
      MailMessage Msg = new MailMessage();
      // Sender e-mail address.
      Msg.From = new MailAddress("pqr@gmail.com");
      // Recipient e-mail address.
      Msg.To.Add("abc@gmail.com");
      Msg.CC.Add("zcd@gmail.com");
      Msg.Subject = "Timesheet Payment Instruction updated";
      Msg.IsBodyHtml = true;
      Msg.Body = emailMessage.ToString();
      SmtpClient smtp = new SmtpClient();
      //smtp.EnableSsl = true;
  
      smtp.Host = ConfigurationManager.AppSettings["HostName"];
      smtp.Port = int.Parse(ConfigurationManager.AppSettings["PortNumber"]);
      smtp.Send(Msg);
      Msg = null;
      Page.RegisterStartupScript("UserMsg", "&lt;script&gt;alert('Mail has been sent successfully.')&lt;/script&gt;");
  }
  catch (Exception ex)
  {
      Console.WriteLine("{0} Exception caught.", ex);
  }
  </code></pre>
  
  <h3>Added this code in web.config</h3>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;appSettings&gt;
      &lt;add key="HostName"   value="The host name as given by my company" /&gt;
      &lt;add key="PortNumber" value="25" /&gt;
  &lt;/appSettings&gt;
  </code></pre>
  
  <p>I keep getting an exception tried changing the port number as specified but no success</p>
  
  <h3>Exception Detail</h3>
  
  <pre><code>  System.Net.Mail.SmtpException was caught
    Message=Failure sending mail.
    Source=System
    StackTrace:
         at System.Net.Mail.SmtpClient.Send(MailMessage message)
         at PAYMENT_DTALinesfollowup.Sendbtn_Click(Object sender, EventArgs e) in d:\AFSS-TFS\AFSS\Code\ERPNET\PAYMENT\DTALinesfollowup.aspx.cs:line 488
    InnerException: System.Net.WebException
         Message=Unable to connect to the remote server
         Source=System
         StackTrace:
              at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress&amp; address, Socket&amp; abortSocket, Socket&amp; abortSocket6, Int32 timeout)
              at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
              at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
              at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
              at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
              at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
              at System.Net.Mail.SmtpClient.GetConnection()
              at System.Net.Mail.SmtpClient.Send(MailMessage message)
         InnerException: System.Net.Sockets.SocketException
              Message=A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 125.63.68.148:25
              Source=System
              ErrorCode=10060
              NativeErrorCode=10060
              StackTrace:
                   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
                   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket&amp; socket, IPAddress&amp; address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception&amp; exception)
              InnerException: 
  </code></pre>