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 に答える