我在使用 Imap 和 MailKit 连接到 Office 365 时遇到问题。我得到的异常是根据验证程序,远程证书无效
https://github.com/jstedfast/MailKit
代码:
imapClient = new ImapClient();
imapClient.Connect("outlook.office365.com", 993, true);
根据文档,我可以将客户端设置为接受所有证书,但我不想这样做。
// For demo-purposes, accept all SSL certificates
imapClient.ServerCertificateValidationCallback = (s,c,h,e) => true;
Microsoft Office 365 设置应该正确:
还有其他人经历过这个问题并解决过吗?
最佳答案
我最终运行了以下代码并在方法中放置了一个断点。
ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
};
发送的证书如下:
certificate.Issuer
"CN=avast! Web/Mail Shield Root, O=avast! Web/Mail Shield, OU=generated by avast! antivirus for SSL/TLS scanning"
停止 Avast Email Protection 后,一切又开始工作。
关于c# - MailKit C# ImapClient.Connect() 到 Office 365 生成异常 : "The remote certificate is invalid according to the validation procedure",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41870986/