如何根据验证程序“修复”远程证书无效。
我将尝试通过MailKit发送电子邮件,但遇到了“ System.Security.authentication.authentication exception”错误的问题,该错误是“根据验证过程无效的远程证书”(丹麦语翻译)我的邮件服务器运行SSL TLS和TLS支持1.2版和1.3版。我的代码如下:我不希望它对太多代码 - 但是我不知道在哪里增强代码,以便它可以正确处理SSL :-(
错误出现在“ client.connect”行中(“ servername”(“ servername”) );
,是的
public void SendMail(string AFromMailAdr, string AFromName, string AToMailAdr, string AToName, string ASubject, string ABody)
{
MimeMessage message = new MimeMessage();
...
using (var client = new MailKit.Net.Smtp.SmtpClient())
{
client.Timeout = 30000;
client.Connect("servername", 587, true);
client.Authenticate("Username", "password");
client.Send(message);
client.Disconnect(true);
}
}
, 587
I am going to try to send emails via Mailkit but ran into problems with the error from "System.Security.Authentication.AuthenticationException" which is "The remote certificate is invalid according to the validation procedure" (translated from danish) My mailserver runs SSL TLS and the TLS supports version 1.2 and 1.3. my code is as below: I do not hope that it is to much code - but I do not know where to enhance the code so it can handle SSL correctly :-(
The error occur in the line "client.Connect("servername", 587, true);"
So my question is: How to avoid this error message via Mailkit?
public void SendMail(string AFromMailAdr, string AFromName, string AToMailAdr, string AToName, string ASubject, string ABody)
{
MimeMessage message = new MimeMessage();
...
using (var client = new MailKit.Net.Smtp.SmtpClient())
{
client.Timeout = 30000;
client.Connect("servername", 587, true);
client.Authenticate("Username", "password");
client.Send(message);
client.Disconnect(true);
}
}
I have googlet a lot until now without finding the correct answer - so therefore I kindly ask here on SO.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
公平地说,应检查/纠正潜在的问题。
您可以控制MailKit如何使用
”您可以在回调函数中返回true; 。
MailKit文档中的代码:
To be fair, the underlying problem should be checked/corrected.
You can control how MailKit does the server certificate validation using a ServerCertificateValidationCallback
For debugging purposes you could
return true;
in the callback function.Code from the MailKit documentation: