gpt4 book ai didi

c# - 通过 C# Mailkit/Mimekit 发送电子邮件但出现服务器证书错误

转载 作者:太空宇宙 更新时间:2023-11-03 12:23:02 28 4
gpt4 key购买 nike

Visual Studio 2015 中的 0 代码

1 我正在使用 Mailkit 最新版本 (1.18.1.1) 从我自己的电子邮件服务器发送电子邮件。

2 电子邮件服务器有一个自签名证书,该证书不受信任。

3 我在我的代码中添加了以下两行,以忽略服务器证书错误:

client.ServerCertificateValidationCallback = (mysender, certificate, chain, sslPolicyErrors) => { return true; };
client.CheckCertificateRevocation = false;

4 但我的程序仍然崩溃。

5 在电子邮件服务器日志中显示错误:

SSL_accept error from unknown[xxx.xxx.xxx.xxx]: Connection reset by peer

我猜这是因为服务器证书问题。因为在 Wireshark 捕获中,一旦我获得 SERVER 证书,连接就会终止。

6 我在我的系统中也安装了电子邮件服务器的 UNTRUSTED 证书,但问题仍然存在。

7 下面是错误的详细截图 enter image description here

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 true; };
client.CheckCertificateRevocation = false;



client.Connect("xxx.com", 465, true);
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");

// Note: only needed if the SMTP server requires authentication
client.Authenticate("xxx@xxx.com","123456");

client.Send(message);
client.Disconnect(true);
}

最佳答案

我的问题已经解决了。在 CONNECT 命令和应用程序 (c#) 开始工作之前,我在我的代码中添加了以下行!!!

client.SslProtocols = System.Security.Authentication.SslProtocols.Tls11;

关于c# - 通过 C# Mailkit/Mimekit 发送电子邮件但出现服务器证书错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46421323/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com