“根据验证程序,远程证书无效。” 使用Gmail SMTP服务器


221

我收到此错误:

根据验证过程,远程证书无效。

每当我尝试使用C#代码使用Gmail的SMTP服务器发送电子邮件时。有人可以指出我正确的方向来解决这个问题吗?

以下是堆栈跟踪...

at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.TlsStream.CallProcessAuthentication(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Mail.SmtpConnection.Flush()
at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at BulkEmail.frmemail.mailsending(String toaddress, String fromaddress, String fromname, String subject, String pwd, String attachements, String mailmessage, String htmlmessage, Int32 i, Int32 j, String replytoaddress)

1
您能告诉我们更多有关使用Gmail SMTP服务器的配置的信息吗?我的幸运猜想:您能否告诉我们更多有关SSL的安全策略(例如使用有效/无效的SSL证书?)。
Brian Clozel 09年

您能给我们一个代码示例,在其中可以重现错误吗?
zaTricky

Answers:


302

警告:请勿在生产代码中使用此代码!

解决方法是,您可以关闭证书验证。只有这样做才能获得由于证书错误而引发错误的确认。

在调用之前调用此方法smtpclient.Send()

    [Obsolete("Do not use this in Production code!!!",true)]
    static void NEVER_EAT_POISON_Disable_CertificateValidation()
    {
        // Disabling certificate validation can expose you to a man-in-the-middle attack
        // which may allow your encrypted message to be read by an attacker
        // https://stackoverflow.com/a/14907718/740639
        ServicePointManager.ServerCertificateValidationCallback =
            delegate (
                object s,
                X509Certificate certificate,
                X509Chain chain,
                SslPolicyErrors sslPolicyErrors
            ) {
                return true;
            };
    }

174
这是黑客,不是修复程序?
LB。

88
很想看到一个修复程序,而不是完全关闭所有安全性。
罗曼·斯塔科夫

71
作为解决安全问题的方法,您可以关闭安全性吗?WTF?
约翰·尼古拉斯

68
由于人们似乎仍然认为这是一个解决方案,因此不得不对此予以否决。它只是把安全关。人,请勿在生产中使用。他甚至这么说。嘘。
MGOwen

51
已投票。我完全同意不应在生产中使用它,我正在制作某些东西的原型。他们碰巧为我提供的测试服务器迫使我使用SSL。使用证书对我来说是很新的东西,所以我只想快速
退出,这真好,

58

这里的链接解决了我的问题。

http://brainof-dave.blogspot.com.au/2008/08/remote-certificate-is-invalid-according.html

我转到Web服务的URL(在出现问题的服务器上),单击IE中的小安全图标,该图标显示了证书。然后,我单击“详细信息”选项卡,单击“复制到文件”按钮,这使我可以将证书导出为.cer文件。在本地获得证书后,便可以按照以下说明将其导入服务器上的证书存储中。

启动一个新的MMC。文件->添加/删除管理单元...单击添加...选择证书,然后单击添加。选中“计算机帐户”单选按钮。点击下一步。

在下一个屏幕中选择客户端计算机。单击完成。单击关闭。单击确定。现在将证书安装到“受信任的根证书颁发机构”证书存储中。这将允许所有用户信任证书。


通过证书上的导入工具而不是通过管理单元导入证书时为+1,它仅适用于您的用户帐户。使用管理单元,您可以选择导入对象,用户帐户,服务帐户或每个人。感谢您的指导。我在那里挠头一两分钟!
davidb

如果要使用命令行在所有dev / test工作站上自动化- certutil -f -p test -importPFX Root devcert.pfxcertutil -f -p test -importPFX MY devcert.pfx。需要在管理命令提示符下运行(假设PFX密码为test
DeepSpace101

如果您使用的是自签名证书进行测试,这是修复它的最佳方法,谢谢T-Rex!
ToastyMallows 2014年

37

您可以通过在证书无效时询问用户是否要继续来改进代码。你想继续吗?如下:

ServicePointManager.ServerCertificateValidationCallback = 
    new RemoteCertificateValidationCallback(ValidateServerCertificate);

并添加如下方法:

public static bool ValidateServerCertificate(object sender,X509Certificate certificate,X509Chain chain,SslPolicyErrors sslPolicyErrors)
{
    if (sslPolicyErrors == SslPolicyErrors.None)
        return true;
    else
    {
        if (System.Windows.Forms.MessageBox.Show("The server certificate is not valid.\nAccept?", "Certificate Validation", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            return true;
        else
            return false;
    }
}

50
如果这是一个云应用程序,谁将单击“继续”按钮?
康斯坦丁·伊萨耶夫

34

晚会晚了一点,但是如果您正在寻找Yury's之类的解决方案,则以下代码将帮助您确定问题是否与自签名证书有关,如果是,请忽略自签名错误。如果需要,您显然可以检查其他SSL错误。

我们使用的代码(由Microsoft提供-http: //msdn.microsoft.com/zh-cn/library/office/dd633677 (v= exchg.80 ) .aspx)如下:

  private static bool CertificateValidationCallBack(
         object sender,
         System.Security.Cryptography.X509Certificates.X509Certificate certificate,
         System.Security.Cryptography.X509Certificates.X509Chain chain,
         System.Net.Security.SslPolicyErrors sslPolicyErrors)
    {
  // If the certificate is a valid, signed certificate, return true.
  if (sslPolicyErrors == System.Net.Security.SslPolicyErrors.None)
  {
    return true;
  }

  // If there are errors in the certificate chain, look at each error to determine the cause.
  if ((sslPolicyErrors & System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors) != 0)
  {
    if (chain != null && chain.ChainStatus != null)
    {
      foreach (System.Security.Cryptography.X509Certificates.X509ChainStatus status in chain.ChainStatus)
      {
        if ((certificate.Subject == certificate.Issuer) &&
           (status.Status == System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.UntrustedRoot))
        {
          // Self-signed certificates with an untrusted root are valid. 
          continue;
        }
        else
        {
          if (status.Status != System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.NoError)
          {
            // If there are any other errors in the certificate chain, the certificate is invalid,
         // so the method returns false.
            return false;
          }
        }
      }
    }

    // When processing reaches this line, the only errors in the certificate chain are 
// untrusted root errors for self-signed certificates. These certificates are valid
// for default Exchange server installations, so return true.
    return true;
  }
  else
  {
 // In all other cases, return false.
    return false;
  }
}

1
就我而言,sslPolicyErrors是RemoteCertificateNameMismatch,我修改了证书检查,因为我们没有相同的Subject和Issuer值。
UfukHacıoğulları16年

2
使用的X509证书Exchange服务器始终在自签名服务器和受信任服务器之间切换。使用此代码不仅帮助我的网络管理员,而且不仅弄清了这种情况,而且还通过绕过自签名证书完全解决了该问题。这太完美了!
Bret

20

我遇到了完全相同的问题,并发现默认情况下,来自Avast防病毒软件的Mail Shield已激活“扫描SSL连接”。确保将其关闭

据我所知,Avast将“打开”该邮件,扫描是否有病毒,然后使用其自己的证书对其进行签名,这样该邮件将不再由gmail的证书进行签名,从而导致该错误。

解决方案1:

  • 关闭防病毒软件(或整个邮件屏蔽)的SSL扫描。

解决方案2(应该是最好的安全性):

  • 以某种方式获取防病毒软件使用的证书(Avast可以选择导出证书)
  • 在连接到Gmail服务器之前,将其导入您的imap / pop / smtp客户端中。

1
你节省了我很多时间。本来会花很长时间才弄清楚我的杀毒软件应该归咎于我,而不是我的代码。
arao6 '16

13

由于SSL导致从Outlook发送邮件时遇到相同的错误。尝试设置EnableSSL = false解决了该问题。

例:

var smtp = new SmtpClient
                {
                    Host = "smtp.gmail.com",                   
                    Port = 587,
                    EnableSsl = false,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,                   
                    Credentials = new NetworkCredential("xxx@gmail.com", "xxxxx")
                };

3
在将SSL设置为false时,gmail不允许您连接,我尝试了对我不起作用的解决方案。
Zeeshan Ajmal

是的,这就是我所说的“基本”(相对于“无”或“ ssl”).......那些电子邮件设置有时会比较棘手。
granadaCoder


9

当我尝试SmtpClient通过代理服务器(Usergate)使用发送电子邮件时,我遇到了相同的错误。

验证包含服务器地址的证书,该地址不等于代理服务器的地址,因此错误。我的解决方案:如果在检查证书时发生错误,请接收证书,将其导出并检查。

public static bool RemoteServerCertificateValidationCallback(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
    {
        if (sslPolicyErrors == SslPolicyErrors.None)
            return true;

        // if got an cert auth error
        if (sslPolicyErrors != SslPolicyErrors.RemoteCertificateNameMismatch) return false;
        const string sertFileName = "smpthost.cer";

        // check if cert file exists
        if (File.Exists(sertFileName))
        {
            var actualCertificate = X509Certificate.CreateFromCertFile(sertFileName);
            return certificate.Equals(actualCertificate);
        }

        // export and check if cert not exists
        using (var file = File.Create(sertFileName))
        {
            var cert = certificate.Export(X509ContentType.Cert);
            file.Write(cert, 0, cert.Length);
        }
        var createdCertificate = X509Certificate.CreateFromCertFile(sertFileName);
        return certificate.Equals(createdCertificate);
    }

我的电子邮件发件人课程的完整代码:

public class EmailSender
{
    private readonly SmtpClient _smtpServer;
    private readonly MailAddress _fromAddress;

    public EmailSender()
    {
        ServicePointManager.ServerCertificateValidationCallback = RemoteServerCertificateValidationCallback;
        _smtpServer = new SmtpClient();
    }

    public EmailSender(string smtpHost, int smtpPort, bool enableSsl, string userName, string password, string fromEmail, string fromName) : this()
    {
        _smtpServer.Host = smtpHost;
        _smtpServer.Port = smtpPort;
        _smtpServer.UseDefaultCredentials = false;
        _smtpServer.EnableSsl = enableSsl;
        _smtpServer.Credentials = new NetworkCredential(userName, password);

        _fromAddress = new MailAddress(fromEmail, fromName);
    }

    public bool Send(string address, string mailSubject, string htmlMessageBody,
        string fileName = null)
    {
        return Send(new List<MailAddress> { new MailAddress(address) }, mailSubject, htmlMessageBody, fileName);
    }

    public bool Send(List<MailAddress> addressList, string mailSubject, string htmlMessageBody,
        string fileName = null)
    {
        var mailMessage = new MailMessage();
        try
        {
            if (_fromAddress != null)
                mailMessage.From = _fromAddress;

            foreach (var addr in addressList)
                mailMessage.To.Add(addr);

            mailMessage.SubjectEncoding = Encoding.UTF8;
            mailMessage.Subject = mailSubject;

            mailMessage.Body = htmlMessageBody;
            mailMessage.BodyEncoding = Encoding.UTF8;
            mailMessage.IsBodyHtml = true;

            if ((fileName != null) && (System.IO.File.Exists(fileName)))
            {
                var attach = new Attachment(fileName, MediaTypeNames.Application.Octet);
                attach.ContentDisposition.CreationDate = System.IO.File.GetCreationTime(fileName);
                attach.ContentDisposition.ModificationDate = System.IO.File.GetLastWriteTime(fileName);
                attach.ContentDisposition.ReadDate = System.IO.File.GetLastAccessTime(fileName);
                mailMessage.Attachments.Add(attach);
            }
            _smtpServer.Send(mailMessage);
        }
        catch (Exception e)
        {
            // TODO lor error
            return false;
        }
        return true;
    }

    public static bool RemoteServerCertificateValidationCallback(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
    if (sslPolicyErrors == SslPolicyErrors.None)
        return true;

    // if got an cert auth error
    if (sslPolicyErrors != SslPolicyErrors.RemoteCertificateNameMismatch) return false;
    const string sertFileName = "smpthost.cer";

    // check if cert file exists
    if (File.Exists(sertFileName))
    {
        var actualCertificate = X509Certificate.CreateFromCertFile(sertFileName);
        return certificate.Equals(actualCertificate);
    }

    // export and check if cert not exists
    using (var file = File.Create(sertFileName))
    {
        var cert = certificate.Export(X509ContentType.Cert);
        file.Write(cert, 0, cert.Length);
    }
    var createdCertificate = X509Certificate.CreateFromCertFile(sertFileName);
    return certificate.Equals(createdCertificate);
}

}


7

我知道我在这场比赛中已经很晚了,但是我没有看到指向TLS流的system.diagnostics日志的答案。

在对代码进行任何更改之前,请确保您了解问题所在。这AuthenticationException是一个非常普通的异常之一,它并不能说明很多问题。要了解幕后情况,请为您的应用程序编辑app.config文件(或创建一个新文件),并确保在该部分中启用了System.Net跟踪源system.diagnostics,例如:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.diagnostics>
    <trace autoflush="true" />
    <sharedListeners>
      <add name="file" initializeData="c:\network.log" type="System.Diagnostics.TextWriterTraceListener" />
    </sharedListeners>
    <sources>
      <source name="System.Net" switchValue="Verbose">
        <listeners>
          <add name="file" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
</configuration>

重新运行您的应用程序,然后检查c:\ network.log文件。您应该在此处看到有关TLS(SSL)连接的详细信息,例如:

System.Net Information: 0 : [12764] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = f44368:535f958, targetName = localhost, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [12764] InitializeSecurityContext(In-Buffers count=2, Out-Buffer length=0, returned code=OK).
System.Net Information: 0 : [12764] Remote certificate: [Version]
  V3

[Subject]
  CN=test
  Simple Name: test
  DNS Name: example.com

[Issuer]
  CN=Root CA
  Simple Name: Root CA
  DNS Name: Root CA

...

[Signature Algorithm]
  sha256RSA(1.2.840.113549.1.1.11)

[Public Key]
  Algorithm: RSA
  Length: 2048
  Key Blob: ....
System.Net Information: 0 : [12764] SecureChannel#38496415 - Remote certificate has errors:
System.Net Information: 0 : [12764] SecureChannel#38496415 -    Certificate name mismatch.
System.Net Information: 0 : [12764] SecureChannel#38496415 - Remote certificate was verified as invalid by the user.
System.Net Error: 0 : [12764] Exception in AppDomain#10923418::UnhandledExceptionHandler - The remote certificate is invalid according to the validation procedure..

知道是什么原因导致了问题,您应该能够解决问题,或者至少缩小Google搜索范围。


6

我的问题是在Windows 2003 Server上,调用AuthenticateAsClient。上面的解决方案(例如,规避ServicePointManager.ServerCertificateValidationCallback)无效。

原来这是Windows 2003中的错误,并且有一个修补程序:

“使用密码技术API的应用程序无法验证Windows Server 2003中的X.509证书”

https://support.microsoft.com/zh-CN/kb/938397

安装此修补程序解决了我的问题。


4

您的网站文件夹需要网络服务安全性。特别是web.config。它使用此帐户访问您的注册表以获取证书。这将不再需要向您的代码中添加hack。


4

我的问题不是我通过IP地址而不是URL来引用服务器。我已经从CA购买了签名证书,供在专用网络内使用。引用服务器时,证书上指定的URL确实很重要。一旦我通过证书中的URL引用了服务器,一切便开始工作。


这个答案应该是最高的,因为它指出了一个常见的错误。人们(包括我自己)都认为Host的目的仅仅是为了找到服务器。
Mojtaba

4

检查计算机的日期和时间。如果不正确,请将其更新为当前时间或自动设置为从Internet获取时间。

因为证书是固定的时间段,所以如果您的时钟错误,您很可能会遇到这样的错误。在这种情况下,通过固定时间,可以解决问题。


1
如果您的系统日期距离当前时间“太远”,那么从Google收到的证书的有效性就会引起问题。它对不花费太多时间的信息发布并有效。这不是唯一不能导致此问题的事情。但肯定可以。
菲尔·萨迪2014年

1
一个非常有用的提醒,请仔细检查我的情况!Occam的Razor以及所有其他... :)现在关于那个CMOS电池...
Mike G


2

在我们的案例中,问题是由IIS服务器证书引起的。证书的主题设置为DNS名称,并且用户试图通过IP地址访问网站,因此.NET证书验证失败。用户开始使用DNS名称时,问题消失了。

因此,您必须将提供者URL更改为https://CertificateSubject/xxx/xxx.application


你能详细说明一下吗?就我而言,应用程序可在一台服务器上运行,而不能在另一台服务器上运行。我一无所知...我不是专家,但是域仍连接到工作中的域,并且两台计算机上均已安装服务器证书。仍然不知道为什么会如此,因为它说“远程证书”。
Michael Brennt '16


1

添加此行对我有用。实际上,这将信任这里提到的所有证书。但是,这主要可用于故障排除。如果这对您有效,则意味着远程服务器的证书未作为您的计算机中的受信任证书添加。

System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(RemoteServerCertificateValidationCallback);

完整的代码是

private void sendAMail(String toAddress, String messageBody)
        {
            String msg = "Sending mail to : " + toAddress;

            MailMessage mail = new MailMessage();
            mail.To.Add(toAddress);
            mail.From = new MailAddress("from@mydomain.com");
            mail.Subject = "Subject: Test Mail";
            mail.Body = messageBody;
            mail.IsBodyHtml = true;            

            //Added this line here
            System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(RemoteServerCertificateValidationCallback);
            SmtpClient smtp = new SmtpClient();

            smtp.Host = "myhostname.com";            
            smtp.Credentials = new System.Net.NetworkCredential("sender@sample.com", "");
            smtp.EnableSsl = true;
            smtp.Port = 587;            
            smtp.Send(mail);            
        }


private bool RemoteServerCertificateValidationCallback(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
    //Console.WriteLine(certificate);
    return true;
}

0

它解决了我的问题

smtpClient.Credentials = new NetworkCredential(sendMail.UserName, sendMail.Password);
smtpClient.EnableSsl = false;//sendMail.EnableSSL;

//仅在出现问题时使用//引用//仅在SMTP设置中输入了用户名和密码时,使用上一行设置错误的SSl来解决错误。


13
这也关闭了安全性。
Zoey 2014年

0

这是我决定使用的解决方案。

        ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            string name = certificate.Subject;

            DateTime expirationDate = DateTime.Parse(certificate.GetExpirationDateString());

            if (sslPolicyErrors == SslPolicyErrors.None || (sslPolicyErrors == SslPolicyErrors.RemoteCertificateNameMismatch && name.EndsWith(".acceptabledomain.com") && expirationDate > DateTime.Now))
            {
                return true;
            }
            return false;
        };

0

接受的答案中的代码帮助我调试了问题。然后,我意识到该certificate参数的SN字段与我认为的SMTP服务器不同。通过将HostSmtpClient实例的属性设置为证书的SN值,我可以解决此问题。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.