title: Cant emails through exchange: An existing connection was forcibly closed by the remote host
body: <p>I just noticed that some of the email operations in my code have been failing and am trying to fix it up, however I keep getting the following error:</p>
  
  <pre><code>System.Net.Mail.SmtpException: Failure sending mail. ---&gt; System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
   ---&gt; System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
     at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
     at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
     --- End of inner exception stack trace ---
     at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
     at System.Net.DelegatedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
     at System.Net.BufferedReadStream.Read(Byte[] buffer, Int32 offset, Int32 count)
     at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)
     at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
     at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
     at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
     at System.Net.Mail.SmtpClient.GetConnection()
     at System.Net.Mail.SmtpClient.Send(MailMessage message)
     --- End of inner exception stack trace ---
     at System.Net.Mail.SmtpClient.Send(MailMessage message)
  </code></pre>
  
  <p>My code is fairly straightforward:</p>
  
  <pre><code>MailMessage mail = new MailMessage();
  mail.To.Add(email_to);
  mail.From = new MailAddress(email_from);
  mail.Subject = email_subject;
  mail.Body = email_body;
  
  
  var client = new SmtpClient(smtp_server_url);
  client.Credentials = new NetworkCredential(username, password, domain);
  client.Timeout = 30000;
  client.Send(mail);
  </code></pre>
  
  <p>Does anyone have any ideas what could be going on? Our exchange server administrator says she can't see anything in the log.</p>
  
  <p>Also, not that this is a surprise, but the same thing happens when I try to send a message from powershell.</p>