C#.net POP3无法连接Gmail(pop.gmail.com,995)

时间:2012-07-18 06:08:36

标签: c# gmail pop3

我正在尝试使用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(主机);在这一行发生了错误

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

请建议我解决这个问题。

1 个答案:

答案 0 :(得分:1)

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

smtpclient.Send()

之前放置此代码
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };