问题
so, i got mailsystem.net from codeplex(http://mailsystem.codeplex.com/), to write pop3 client. problem is, i want to use http proxy. found some hints at:
How to open socket thru proxy server in .Net C#?
and here is my code:
Pop3Client pop = new Pop3Client();
Socket sock = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
sock.Connect("79.172.35.74", 82); // here is proxy
sock.Send(Encoding.UTF8.GetBytes("CONNECT pop.yandex.ru:110 HTTP/1.1<CR><LF>")); // here pop3 server
sock.Send(Encoding.UTF8.GetBytes("<CR><LF>"));
byte[] buffer = new byte[25];
sock.Receive(buffer);
pop.Client = sock;
pop.Connect(config.pop3.host, config.pop3.username, config.pop3.password);
so, it fails at last line, with socket exception. what can i do? or any free pop3client libraries with proxy support?
回答1:
Quote from the post you link to:
- Connect to proxy.
- Issue
CONNECT Host:Port HTTP/1.1<CR><LF>
- Issue
<CR><LF>
- Wait for a line of response. If it contains
HTTP/1.X 200
, the connection is successful.- Read further lines of response until you receive an empty line.
- Now, you are connected to the outside world through a proxy. Do any data exchange you want.
Where is it that you do bullet nr. 5? Where do you read all lines until you receive an empty line?
Other then that, I do not know what the problem might be. You could choose to use Starksoft Proxy library to help you.
回答2:
This line:
pop.Connect(config.pop3.host, config.pop3.username, config.pop3.password);
is not needed, your socket is already connected. You should only log in.
You may try Mail.dll POP3 component. Please note that it's a commercial (not free) product that I've created.
It supports HTTP and SOCKS proxies:
http://www.lesnikowski.com/blog/index.php/imap-pop3-smtp-via-http-socks-proxy/
来源:https://stackoverflow.com/questions/5248269/net-pop3-over-http-proxy