“根據驗證程序,遠程證書無效?!?使用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)