微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

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

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

调用之前调用方法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;
            };
    }

解决方法

我收到此错误:

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

每当我尝试使用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,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.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 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)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。