title: "Unable to connect to the remote server" Error
body: <p>I'm trying to send an email from my website.</p>
  
  <p>this is my code:</p>
  
  <pre><code>public string SendEmail()
      {
      string sMessage;
      SmtpClient smtpClient = new SmtpClient("mail.test.com",25);
      MailMessage message = new MailMessage();
      try
          {
           smtpClient.Credentials = new System.Net.NetworkCredential("web", "test1234", "myDomain");
           MailAddress fromAddress = new MailAddress("web@test.com", "web");
  
           message.From = fromAddress;
           message.To.Add("test@gmail.com"); 
           message.Subject = "test";
           message.Body = "TEST";
           message.IsBodyHtml = true;
           smtpClient.EnableSsl = false; 
           smtpClient.Send(message);
           sMessage = "Email sent.";
          }
          catch (Exception ex)
          {
              sMessage = "Coudn't send the message!\n " + ex.Message;
          }
          return "";
      }
  </code></pre>
  
  <p>But I'm getting the following error:</p>
  
  <blockquote>
    <p>"Unable to connect to the remote server" </p>
  </blockquote>
  
  <p>The data (host name, port, credentials) is correct, I checked it in a few SMTP checkers (for ex <a href="http://smtper.nanogenesis.fr/" rel="nofollow noreferrer">this one</a>) and it worked fine.</p>
  
  <p>I tried everything I found online:</p>
  
  <pre><code>smtpClient.UseDefaultCredentials = false;
  smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
  </code></pre>
  
  <p>And different ports but nothing helped, I keep getting the error.</p>
  
  <p>What am I doing something wrong? Am I missing something? </p>