title: Asp.Net Core MailKit: The remote certificate is invalid according to the validation proceedure
body: <p>I have a question regarding email sending on asp.net core.</p>
  
  <p>So I have this code:</p>
  
  <pre><code>private void SendEmailLocalSMTP(string email, string subject, string message)
  {
          MimeMessage mailMsg = new MimeMessage();
  
          //TESTING ENVIRONMENT ONLY!!!
          mailMsg.To.Add(new MailboxAddress("myMail@gmail.com", "cjimenezber@gmail.com"));
  
          // From
          mailMsg.From.Add(new MailboxAddress("noreply@app.com", "Facturacion"));
  
          // Subject and multipart/alternative Body
          mailMsg.Subject = subject;
          string html = message;
  
          System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("myMail@gmail.com", "myPassword");
  
          // Init SmtpClient and send
          using (var client = new SmtpClient())
          {
              client.Connect("smtp.gmail.com", 587, SecureSocketOptions.StartTls);
              client.AuthenticationMechanisms.Remove("XOAUTH2");
              client.Authenticate(credentials);
              client.Send(mailMsg);
              client.Disconnect(true);
          }
      }
  </code></pre>
  
  <p>From what I have found in other posts somewhat related, this should be enough to send it using MailKit, however it's not working properly. I am getting the following exception and I don't know how to proceed from here.</p>
  
  <p>This is the exception:</p>
  
  <p><a href="https://i.stack.imgur.com/HYccA.png" rel="noreferrer"><img src="https://i.stack.imgur.com/HYccA.png" alt="enter image description here"></a></p>
  
  <p>I've seen this question, but I haven't made much sense from it: <a href="https://stackoverflow.com/questions/33496290/how-to-send-email-by-using-mailkit">How to send email by using MailKit?</a></p>
  
  <p>Any help is highly appreciated, thanks.</p>