2017-01-26 38 views
1

使用Imap和MailKit連接到Office 365時出現問題。我得到的例外是The remote certificate is invalid according to the validation procedureMailKit C#ImapClient.Connect()到Office 365生成異常:「根據驗證過程,遠程證書無效」

https://github.com/jstedfast/MailKit

代碼:

imapClient = new ImapClient(); 

imapClient.Connect("outlook.office365.com", 993, true); 

據我可以設置客戶端接受所有證書,但我不wan't做到這一點的文檔。

// 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

有其他人遇到這樣和解決它?

回答

1

我結束了運行下面的代碼,並在該方法中放置一個斷點。

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的電子郵件保護後,一切都開始工作了。

相關問題