title: Error : A connection attempt failed because the connected party did not properly respond after a period of time
body: <p>I got the Error:  </p>
  
  <blockquote>
    <p>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 <strong>.<em></strong>.<strong></em>.*</strong>:25</p>
  </blockquote>
  
  <p>when I sending the mail on the server.</p>
  
  <p>I tried this solution but I still got the same error.</p>
  
  <p>The problem was that the line
  <code>IPAddress IP = IPAddress.Parse(ipStr);</code> of the server program should have been <code>IPAddress IP = IPAddress.Any;</code></p>
  
  <p>Here, I created one function to send mail.</p>
  
  <pre><code>private static void SetUserCredentialAndProcessMail(MailMessage msg, string mailTo)
  {
      NetworkCredential networkCredential = new NetworkCredential(SendMail.userName, SendMail.password);
      SmtpClient smtpClient = new SmtpClient(SendMail.smtpServer, SendMail.SmtpPort);
      smtpClient.EnableSsl = SendMail.testMode == "1";
      smtpClient.UseDefaultCredentials = false;
      smtpClient.Credentials = (ICredentialsByHost)networkCredential;
      try
      {
              MailMessage message = new MailMessage(SendMail.mailFrom, mailTo, msg.Subject, msg.Body);
              message.IsBodyHtml = msg.IsBodyHtml;
              if (msg.Attachments != null &amp;&amp; msg.Attachments.Count &gt; 0)
              {
                  foreach (Attachment attachment in (Collection&lt;Attachment&gt;)msg.Attachments)
                      message.Attachments.Add(attachment);
              }
              smtpClient.Send(message);
      }
      catch (Exception ex)
      {
          throw ex;
      }
  }
  </code></pre>
  
  <p>What could be the reasons for such an error..???</p>