c# - MailKit C# ImapClient.Connect() 到 Office 365 生成异常 : "The remote certificate is invalid according to the validation procedure"

标签 c# office365 mailkit

我在使用 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 设置应该正确:

https://support.office.com/en-us/article/POP-and-IMAP-settings-for-Outlook-Office-365-for-business-7fc677eb-2491-4cbc-8153-8e7113525f6c

还有其他人经历过这个问题并解决过吗?

最佳答案

我最终运行了以下代码并在方法中放置了一个断点。

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/

相关文章:

c# - MailKit:当 Gmail 设置“对话” View 时,消息不会从收件箱中删除

c# - 使用 Mailkit : "The SMTP server has unexpectedly disconnected."

c# - 使用asp.net页从另一台服务器访问文件

c# - XBAP 中的键盘快捷键

Excel 跨列唯一

email - 如何使用 MailKit POP3 客户端通过消息 ID 删除消息?

c# - 将巨大的 xml 参数传递给存储过程的最佳方法

c# - 从C#运行BCP时检测错误

excel - 自动化错误。通过 Selenium 和 VBA 使用 Excel 的灾难性故障错误

rest - 从 Office 365 日历获取所有事件