Raj
Raj

Reputation: 361

C#.net POP3 unable to connect Gmail (pop.gmail.com, 995)

I am trying to connect gmail using C# pop3 but it give an error that : The remote certificate is invalid according to the validation procedure.

I use the given below code to connect

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();
            }

here my host is "pop.gmail.com" and port is "995"

secureStream.AuthenticateAsClient(Host); at this line the error has been occurred

"The remote certificate is invalid according to the validation procedure."

Please suggest me something to solve this issue..

Upvotes: 1

Views: 2773

Answers (1)

PraveenVenu
PraveenVenu

Reputation: 8337

As a workaround, you can switch off certificate validation

put this code somewere before smtpclient.Send():

ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };

Upvotes: 1

Related Questions