+2 votes

I am using the following code to connect to a pop 3 using a http proxy.

The proxy works, it's IP authorized and works good in firefox or with normal HttpWebRequest c#.

Here is the code I use:

ProxyFactory factory = new ProxyFactory();
IProxyClient proxy = factory.CreateProxy(ProxyType.Http,prox.ip,prox.port);
Socket socket = proxy.Connect("pop.aol.com",995);

socket = proxy.Connect("pop.aol.com",995);
poppy.AttachSSL(socket, "pop.aol.com");

poppy.Connect("pop.aol.com",995,true);

On poppy.Connect I get the following:
Once the socket has been disconnected, you can only reconnect again ....

What can be the cause of this?

Really need your help, just purchased this awesome library you made and I need it to implement it asap.

by

1 Answer

0 votes
 
Best answer

You are using too many Connects.

Use single Connect on proxy object and AttachSSL on Pop3 class. No other
connects are needed.

ProxyFactory factory = new ProxyFactory();
IProxyClient proxy = factory.CreateProxy(
    ProxyType.Http, prox.ip, prox.port);
Socket socket = proxy.Connect("pop.aol.com", Pop3.DefaultSSLPort);

using(Pop3 pop3 = new Pop3())
{
    pop3.AttachSSL(socket, "pop.aol.com");

    // ...

    pop3.Close();
}

Notice additional parameter to AttachSSL method: "pop.aol.com". This is a target host required for SSL negotiation.

by (297k points)
I am facing the same issue.
below is my code:

 ProxyFactory factory = new ProxyFactory();
                IProxyClient proxy = factory.CreateProxy(ProxyType.Http, uriProxy.Host, uriProxy.Port);
                Socket socket = proxy.Connect(server, Imap.DefaultPort);

                using (Imap imap = new Imap())
                {
                    imap.Attach(socket);

                    imap.ServerCertificateValidate += Validate;
                    imap.ConnectSSL(server);//Port 993                  
                    imap.Login(username, userpassword);

it gives me error "Once the socket has been disconnected, you can only reconnect again asynchronously, and only to a different EndPoint.  BeginConnect must be called on a thread that won't exit until the operation has been completed."

Please help.
Don't use ConnectSSL - socket is already connected by using proxy.Connect. Use AttachSSL as in my answer above
...