title: Unable to connect to the remote server C#
body: <p>I made this console application which scans over a folder for files and sends them via email as attachments.It works fine in my local machine. But when I try to run it remotely on another machine(testing server), it gives me an exception.</p>
  
  <p>This is exception that I see. </p>
  
  <pre><code> innerException  {System.Net.WebException: Unable to connect to the remote server ---&gt; System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions *******:25
         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, Exception&amp; exception)
         --- End of inner exception stack trace ---
         at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress&amp; address, Socket&amp; abortSocket, Socket&amp; abortSocket6)
         at System.Net.PooledStream.Activate(Object owningObject, Boolean async, 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)} System.Exception {System.Net.WebException}
  </code></pre>
  
  <p>I'm not sure why would this work on on my local machine and not on the server. Is that because an outlook account is not set up at the server ? </p>
  
  <p>This is the mailing code in my application - </p>
  
  <pre><code>public static void SendMailMessage(string file) 
  {
      const string subject = "TESTING";
      const string body = "";
  
      string from = ConfigurationManager.AppSettings["from"];        
      string to = ConfigurationManager.AppSettings["to"];
      var message = new MailMessage(from, to, subject, body);
      message.Attachments.Add(new Attachment(file));
      var client = new SmtpClient("smtp.mail***.com")
      {
          DeliveryMethod = SmtpDeliveryMethod.Network,
          UseDefaultCredentials = true
  
      };
  
      try
      {
          client.Send(message);
          Console.WriteLine("Email Successfully sent!");
  
      }
      catch (Exception e)
      {
          Console.WriteLine(e.Message);
      }
  }
  </code></pre>