POP3 with SSL

Apr 5, 2012 at 6:25 PM

Hi,

I downloaded the latest source code avalaible.

I tryed to connect the Pop3Client to my exchange server, but I can't ..

My test code:

 using (var client = new Pop3Client())
            {
                client.Security = SecurityPolicies.Explicit;
                client.Connect("exchange.myServer.com", Pop3Ports.Ssl);
                bool res = client.Authenticate(new NetworkCredential("toto", "secret"), SaslMechanics.Login);

==> res is FALSE...

 

I wrote my own Pop3 client, using a SslStream, and I obtain a "OK+" ! (see below the code of my 2nd test).

Where do I made a mistake in calling Equinox.Pop3Client ?


            tcpClient = new TcpClient(Host, Port);

            instream = new SslStream(tcpClient.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), new LocalCertificateSelectionCallback(SelectLocalCertificate));
            instream.AuthenticateAsClient(Host);
                      
            IsOpen = true;

            bts = new byte[2048];
            res = instream.Read(bts, 0, bts.Length);
            response.Add(wstr = Encoding.ASCII.GetString(bts, 0, res));

            if (wstr.Substring(0, 3) != "+OK")
            {
                throw new Pop3Exception(Host, Username, wstr);
            }

            //
            instream.Write(Encoding.ASCII.GetBytes("USER " + Username + "\r\n"));
            bts = new byte[2048];
            res = instream.Read(bts, 0, bts.Length);
            response.Add(wstr = Encoding.ASCII.GetString(bts, 0, res));

            if (wstr.Substring(0, 3) != "+OK")
            {
                throw new Pop3Exception(Host, Username, wstr);
            }
            //
            instream.Write(Encoding.ASCII.GetBytes("PASS " + Password + "\r\n"));
            bts = new byte[2048];
            res = instream.Read(bts, 0, bts.Length);
            response.Add(wstr = Encoding.ASCII.GetString(bts, 0, res));

            if (wstr.Substring(0, 3) != "+OK")
            {
                throw new Pop3Exception(Host, Username, wstr);
            }

 

 

 

 

Coordinator
Apr 5, 2012 at 6:42 PM
Edited Apr 5, 2012 at 7:18 PM

Hi,

I am unsure as to what causes this behaviour.

You can however build equinox yourself in Debug Mode. By doing so you can observe traffic from and to the server in the Debug window.

This way you will quickly find the reason for the defect.

Regards

Alexander

Apr 5, 2012 at 8:21 PM

Hi Alexander,

Thank for your quick response.

The 1rst step client.Connect(…) is OK (I receive +OK for each command…)

 But I have an IOException when sending "AUTH LOGIN toto   secret":    Unable to write data to the transport connection: Connection aborted by host…

Regards,

Didier

 

Coordinator
Apr 6, 2012 at 10:30 AM

Hi,

unfortunately I am currently unable to reproduce this behaviour, for I don't have access to an SSL encrypted pop3 server right now.

However you could check whether your SSL Certificate is valid, for the client rejects invalid or invalidatable certificates by default.

You can subscribe to the 'RemoteCertificateValidationFailed' event and accept manually.

Beyond this I can't speculate as to why the connection gets aborted.

Alexander