title: Attempt was made to access a socket in a way forbidden by its access permissions
body: <p>I'm using smtp google's server to send a email through my contact form..In local server it works fine but in web server it shows this error.First ,I've used port number <strong>587</strong> which gives error "Security Exception" and error was on the line <code>using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))</code>, but I've changed port to <strong>25</strong> and it gives this new error on the line .</p>
  
  <pre><code>smtp.Send(mail);
  </code></pre>
  
  <p><strong>Description</strong>: </p>
  
  <blockquote>
    <p>An unhandled exception occurred during the execution of the current
    web request. Please review the stack trace for more information about
    the error and where it originated in the code.</p>
  </blockquote>
  
  <p><strong>Exception Details</strong>:</p>
  
  <blockquote>
    <p>System.Net.Sockets.SocketException: An attempt was made to access a
    socket in a way forbidden by its access permissions 74.125.206.108:25</p>
  </blockquote>
  
  <p>My code is:</p>
  
  <pre><code>protected void send_Click(object sender, EventArgs e)
  {
      string smtpAddress = "smtp.gmail.com";
      int portNumber = 25;
      bool enableSSL = true;
  
      string emailfrom = "isl@gmail.com";
      string password = "******";
      string subject = "Contact Form Data";
      string emailto = "isl@gmail.com";
      string name = n.Value;       
      string useremail = em.Value;
      string phone = tel.Value;
      string dept = dep.Value;
      string dest = des.Value;
      string adu = ad.Value;
  
      string msg = mes.Value;
      string body = "Name: " + name + " ;" + " Email: " + useremail + " ;" + "Telephone: " + phone + " ;" + " Departure Place: " + dept + " ;" + "Destination Place: " + dest + " ;" + " Adults: " + adu + " ;" + " ;" + "Children: " + chil + " ;" + "Message: " + msg + " ;";
  
      using (MailMessage mail = new MailMessage())
      {
          mail.From = new MailAddress(emailfrom);
          mail.To.Add(emailto);
          mail.Subject = subject;
          mail.Body = body;
          mail.IsBodyHtml = true;
  
          using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
          {
              smtp.Credentials = new NetworkCredential(emailfrom, password);
              smtp.EnableSsl = enableSSL;
              smtp.Send(mail);
          }
      }
  }
  </code></pre>
  
  <p><strong>Stack Trace</strong></p>
  
  <blockquote>
    <p>[SocketException (0x271d): An attempt was made to access a socket in a
    way          forbidden by its access permissions 74.125.206.108:25]
    System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,
    SocketAddress socketAddress) +208
    System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure,
    Socket s4, Socket s6, Socket&amp; socket, IPAddress&amp; address,
    ConnectSocketState state, IAsyncResult asyncResult, Exception&amp;
    exception) +464</p>
    
    <p>[WebException: Unable to connect to the remote server]
    System.Net.ServicePoint.GetConnection(PooledStream PooledStream,
    Object owner, Boolean async, IPAddress&amp; address, Socket&amp; abortSocket,
    Socket&amp; abortSocket6) +6662436 System.Net.PooledStream.Activate(Object
    owningObject, Boolean async, GeneralAsyncDelegate asyncCallback) +307
    System.Net.PooledStream.Activate(Object owningObject,
    GeneralAsyncDelegate asyncCallback) +19
    System.Net.ConnectionPool.GetConnection(Object owningObject, 
    GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +324
    System.Net.Mail.SmtpConnection.GetConnection(ServicePoint
    servicePoint) +141
    System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
    +170 System.Net.Mail.SmtpClient.GetConnection() +44 System.Net.Mail.SmtpClient.Send(MailMessage message) +1554</p>
    
    <p>[SmtpException: Failure sending mail.] 
    System.Net.Mail.SmtpClient.Send(MailMessage message) +1906
    Contact.send_Click(Object sender, EventArgs e) in
    \smb-whst-www02\whst_www02$\ff8b1b\user\medviewair.uk\web\Contact.aspx.cs:51
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628462
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String
    eventArgument) +103 
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
    eventArgument) +10
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    sourceControl, String eventArgument) +13
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    +35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    +1724</p>
  </blockquote>