title: Send email using Outlook.com SMTP
body: <p>I am trying to send an automated email using Outlook.com smtp support. However I am get the following exception:</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" Exception while sending email.
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>    public bool SendEmail(MailMessage msg)
      {
          try
          {
              SmtpClient smtpClient = new SmtpClient("smtp-mail.outlook.com")
              {
                  UseDefaultCredentials = false,
                  DeliveryMethod = SmtpDeliveryMethod.Network,
                  Credentials = new NetworkCredential("userAddress", "userPassword"),
                  Port = 587,
                  EnableSsl = true,
              };
              smtpClient.Send(msg);
              msg.Dispose();
              smtpClient.Dispose();
              return true;
          }
          catch (Exception exp)
          {
              Console.WriteLine(exp.ToString());
              return false;
          }
      }
  </code></pre>