title: Mailkit SMTP - StartTLS & TLS flags
body: <p>I am trying to connect to iCloud via SmtpClient</p>
  
  <p>The settings I am using are as follows:</p>
  
  <p>Server name: smtp.mail.me.com<br>
  SSL Required: Yes<br>
  <em>If you see an error message when using SSL, try using TLS or STARTTLS instead.</em><br>
  Port: 587<br>
  SMTP Authentication Required: Yes - with relevant username and password</p>
  
  <p>If I use SSL I get "Handshake failed due to unexpected packet format"</p>
  
  <p>If I don't use SSL visual studio debugger hangs on connect.</p>
  
  <p>I think the problem is I am not telling the SmtpClient to use tls but I cant find documentation on how to do this.</p>
  
  <p>The code is as follows:</p>
  
  <pre><code>using (var client = new SmtpClient()) {
      client.Timeout = 1000 * 20;
      //client.Capabilities.
      client.AuthenticationMechanisms.Remove ("XOAUTH2");
  
      client.Connect("SMTP.mail.me.com", 587, false); //dies here
      //client.Connect(servername, port, useSsl);
      //can I set tls or starttls here??
      client.Authenticate(username, password);
      client.Send(FormatOptions.Default, message);
  }
  </code></pre>
  
  <p>Am I able to set TLS or StartTLS manually. One thing I did try is the following but it did not seem to work</p>
  
  <pre><code>client.Connect(new Uri("smtp://" + servername + ":" + port + "/?starttls=true"));
  </code></pre>
  
  <p>Thanks for any help with this.</p>