【问题标题】:Self Sign certificate on email server电子邮件服务器上的自签名证书
【发布时间】:2013-12-18 19:54:50
【问题描述】:

我正在使用测试email server 在 SSL 环境中测试我的代码。我使用以下命令创建了一个自签名根和一个签名证书。

我写了一个简单的测试程序,使用SmtpClient发送测试邮件,代码如下:

                System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage(tFrom.Text, tTo.Text);

                mm.Subject = tSubject.Text;
                mm.Body = tBody.Text;

                SmtpClient client = new SmtpClient(tSmtp.Text, Convert.ToInt32(tPort.Text));
                client.UseDefaultCredentials = false;

                if (!String.IsNullOrEmpty(tPass.Text) && !String.IsNullOrEmpty(tUser.Text))
                {
                    client.EnableSsl = true;
                    client.Credentials = new NetworkCredential(tUser.Text, tPass.Text);
                }
                client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);
                client.SendAsync(mm, null);

在我的服务器 (Smtp4Dev) 上,我已将其设置为接受 TLS 连接

在我的客户端机器上,我有以下内容:

然而,每当我发送电子邮件时,我都会在服务器日志中收到如下错误:

 220 Ready to start TLS
 Session ended abnormally.
 System.NotSupportedException: The server mode SSL must use a certificate with the associated private key.

如果我在没有 SSL 的情况下尝试此操作,那么我可以正常接收电子邮件。我尝试在个人和受信任的根证书下添加证书,但仍然出现相同的错误。我对 SSL 很陌生,所以希望您能指出正确的方向。

【问题讨论】:

    标签: c# ssl smtp


    【解决方案1】:

    看看实现ServerCertificateValidationCallback 委托。在使用 SmtpClient 之前尝试这样的操作:

    System.Net.ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };
    

    在开发环境中返回 true 并因此接受所有证书只是一个好主意,但您可以扩展委托实现以检查其他属性,而不仅仅是盲目地为所有内容返回 true。

    【讨论】:

      猜你喜欢
      • 2017-06-08
      • 2019-07-25
      • 1970-01-01
      • 1970-01-01
      • 2014-07-23
      • 1970-01-01
      • 2011-08-15
      • 2011-08-12
      • 1970-01-01
      相关资源
      最近更新 更多