0 Code in Visual Studio 2015
1 I am using Mailkit latest version (1.18.1.1) for sending an email from my own email server.
2 The email server is having a self signed certificate, which is not TRUSTED.
3 I have added both of the following lines in my code, to ignore the SERVER CERTIFICATE error:
client.ServerCertificateValidationCallback = (mysender, certificate, chain, sslPolicyErrors) => { return true; };
client.CheckCertificateRevocation = false;
4 But my program still crashes.
5 In email server logs it shows the error:
SSL_accept error from unknown[xxx.xxx.xxx.xxx]: Connection reset by peer
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.
6 I have also installed the UNTRUSTED certificate of email server in my system but still the problem persists.
7 Following is the detailed screenshot of error
8 Complete code:
using (var client = new SmtpClient(new ProtocolLogger("logging.log")))
{
// For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
client.ServerCertificateValidationCallback = (mysender, certificate, chain, sslPolicyErrors) => { 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);
}