1

我正在尝试使用 C# pop3 连接 gmail,但它给出了一个错误:根据验证过程,远程证书无效。

我使用下面给出的代码进行连接

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Xml;


    public void Connect()
            {
                if (Client == null)
                    Client = new TcpClient();
                if (!Client.Connected)
                    Client.Connect(Host, Port);
                if (IsSecure)
                {
                    SslStream secureStream = new SslStream(Client.GetStream());
                    secureStream.AuthenticateAsClient(Host);
                    ClientStream = secureStream;
                    secureStream = null;
                }
                else
                    ClientStream = Client.GetStream();
                Writer = new StreamWriter(ClientStream);
                Reader = new StreamReader(ClientStream);
                ReadLine();
                Login();
            }

这里我的主机是“pop.gmail.com”,端口是“995”

secureStream.AuthenticateAsClient(Host); 在这一行发生了错误

“根据验证程序,远程证书无效。”

请给我一些解决这个问题的建议..

4

1 回答 1

1

作为一种解决方法,您可以关闭证书验证

把这段代码放在前面smtpclient.Send()

ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
于 2012-07-18T06:19:46.383 回答