title: Sending email via C# Mailkit / Mimekit but server certificate error comes in
body: <p>0 Code in Visual Studio 2015</p>
  
  <p>1 I am using Mailkit latest version (1.18.1.1) for sending an email from my own email server. </p>
  
  <p>2 The email server is having a self signed certificate, which is not TRUSTED.</p>
  
  <p>3 I have added both of the following lines in my code, to ignore the SERVER CERTIFICATE error:</p>
  
  <pre><code>client.ServerCertificateValidationCallback = (mysender, certificate, chain, sslPolicyErrors) =&gt; { return true; };
  client.CheckCertificateRevocation = false;
  </code></pre>
  
  <p>4 But my program still crashes. </p>
  
  <p>5 In email server logs it shows the error:</p>
  
  <blockquote>
    <p>SSL_accept error from unknown[xxx.xxx.xxx.xxx]: Connection reset by
    peer</p>
  </blockquote>
  
  <p>which I guess is coming because of the Server Certificate issue. Because in Wireshark capture, as soon as I get the SERVER certificate the connection is terminated. </p>
  
  <p>6 I have also installed the UNTRUSTED certificate of email server in my system but still the problem persists.</p>
  
  <p>7 Following is the detailed screenshot of error
  <a href="https://i.stack.imgur.com/P2TJV.png" rel="noreferrer"><img src="https://i.stack.imgur.com/P2TJV.png" alt="enter image description here"></a></p>
  
  <p>8 Complete code:</p>
  
  <p>using (var client = new SmtpClient(new ProtocolLogger("logging.log")))</p>
  
  <pre><code>                    {
  
                          // For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
                          client.ServerCertificateValidationCallback = (mysender, certificate, chain, sslPolicyErrors) =&gt; { return true; };
                          client.CheckCertificateRevocation = false;
  
  
  
                          client.Connect("xxx.com", 465, true);
                          // Note: since we don't have an OAuth2 token, disable
                          // the XOAUTH2 authentication mechanism.
                          client.AuthenticationMechanisms.Remove("XOAUTH2");
  
                          // Note: only needed if the SMTP server requires authentication
                          client.Authenticate("xxx@xxx.com","123456");
  
                          client.Send(message);
                          client.Disconnect(true);
  }
  </code></pre>