Apr 29, 2014 at 11:01 AM
Edited Apr 29, 2014 at 11:05 AM
Hi, I'm trying to connect via SSL/STARTTLS to the server featuring a self-signed certificate, but I get an AuthenticationException telling me "The remote certificate is invalid according to the validation procedure.".
public bool TryConnectToMailbox(MailSeverAuthInfo mailServerAuth, bool ssl = false, bool tls = false)
            // IMAP mail stuff
            if (_imapClient == null)
                _imapClient = new Imap4Client();

            if (ssl)
                _imapClient.ConnectSsl(mailServerAuth.ServerPath, mailServerAuth.Port);
            else if (tls)
                var sslhandshake = new SslHandShake(mailServerAuth.ServerPath, System.Security.Authentication.SslProtocols.Tls);
                _imapClient.ConnectSsl(mailServerAuth.ServerPath, mailServerAuth.Port, sslhandshake);
                _imapClient.Connect(mailServerAuth.ServerPath, mailServerAuth.Port);
            _imapClient.LoginFast(mailServerAuth.Username, mailServerAuth.Password);
            _mailProvider = _imapClient.SelectMailbox(mailServerAuth.RootFolder);

            return _imapClient.IsConnected;
thank you in advance for the reply.
Mar 4, 2015 at 1:14 PM
Edited Mar 4, 2015 at 1:15 PM
SslHandShake allows you to specify a delegate to perform the certificate validation.
Try passing a delegate that always returns true?
new SslHandShake(mailServerAuth.ServerPath, SslProtocols.Default, (sender,cert,chain,errors) => true);