SMTP SSL:根据验证过程,远程证书无效

时间:2019-06-12 08:15:30

标签: vb.net ssl smtp

我们的一位客户在为SMTP创建了新的SSL认证后遇到了问题。 Outlook通过发送和接收电子邮件与SSL配合良好,但是在vb.net中,SMTP客户端抛出错误,因为“根据验证过程,远程证书无效。”

当smtpClinet.UseSSL = false时,则工作正常。

建议客户端将链式证书添加到当前用户和本地计算机的“受信任的根证书颁发机构”。

问题未解决。

这是在SMTPclient obj中设置的代码:

     oSMTPclient = New SmtpClient() With {
          .UseDefaultCredentials = False
      }

      If sDomain = "" Then
          oSMTPclient.Credentials = New NetworkCredential(sUser, sPassword)
      Else
          oSMTPclient.Credentials = New NetworkCredential(sUser, sPassword, sDomain)
      End If

      oSMTPclient.Host = sHost
      oSMTPclient.Port = iPort
      oSMTPclient.EnableSsl = bSSL

      sMailFromAddress = sFromAddress
      sMailFromAlias = sFromAlias


After I read some in stakoverflow, planning to add the below in code. Will it solve the problem? As its in client end, I cant try in my local.

Private Shared Function customCertValidation(ByVal sender As Object, ByVal cert As X509Certificate, ByVal chain As X509Chain, ByVal errors As SslPolicyErrors) As Boolean

      Return True

  End Function

ServicePointManager.ServerCertificateValidationCallback = New Security.RemoteCertificateValidationCallback(AddressOf customCertValidation)
      ServicePointManager.Expect100Continue = True



In client end, have to give workaround for SMTP over SSL to work. 

0 个答案:

没有答案