There are two most likely reasons of this error:
Incorrect host name: host name must match the name on certificate.
For example imap.example.com and example.com may point to the same server, but certificate is issued only to imap.example.com and this is the address you should use).
Your server is using self-signed certificate
You can accept self-signed certificates using Mail.dll. You need to subscribe to ServerCertificateValidate event:
client.ServerCertificateValidate +=
(sender, e) => { e.IsValid = true; };
client.ConnectSSL("server.example.com");
More correct approach is not to accept any certificate blindly, but allow only certain certificates and certain error types:
using (Imap client = new Imap())
{
client.ServerCertificateValidate +=
new ServerCertificateValidateEventHandler(Validate);
client.ConnectSSL("server.example.com");
client.UseBestLogin("user@example.com", "password");
// IMAP access code goes here.
client.Close();
}
private static void Validate(
object sender,
ServerCertificateValidateEventArgs e)
{
const SslPolicyErrors ignoredErrors =
// self-signed
SslPolicyErrors.RemoteCertificateChainErrors
// name mismatch
| SslPolicyErrors.RemoteCertificateNameMismatch;
string nameOnCertificate = e.Certificate.Subject;
if ((e.SslPolicyErrors & ~ignoredErrors) == SslPolicyErrors.None)
{
e.IsValid = true;
return;
}
e.IsValid = false;
}
You can find details here:
https://www.limilabs.com/blog/the-remote-certificate-is-invalid-according-to-the-validation-procedure