Visual Studio 2015 中的 0 代码
1 我正在使用 Mailkit 最新版本 (1.18.1.1) 从我自己的电子邮件服务器发送电子邮件。
2 电子邮件服务器具有不受信任的自签名证书。
3 我在代码中添加了以下两行,以忽略服务器证书错误:
client.ServerCertificateValidationCallback = (mysender, certificate, chain, sslPolicyErrors) => { return true; };
client.CheckCertificateRevocation = false;
Run Code Online (Sandbox Code Playgroud)
4 但我的程序仍然崩溃。
5 在电子邮件服务器日志中显示错误:
来自未知 [xxx.xxx.xxx.xxx] 的 SSL_accept 错误:连接被对等方重置
我猜这是因为服务器证书问题。因为在 Wireshark 捕获中,一旦我获得 SERVER 证书,连接就会终止。
6 我还在我的系统中安装了不受信任的电子邮件服务器证书,但问题仍然存在。
8 完整代码:
使用 (var client = new SmtpClient(new ProtocolLogger("logging.log")))
{
// For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
client.ServerCertificateValidationCallback = (mysender, certificate, chain, sslPolicyErrors) => { return …Run Code Online (Sandbox Code Playgroud)