public static bool IsValidAccount(string hostname, int port, string username, string password, string proxyIp, int proxyPort)
var client = new Pop3Client();
var tcpClient = ProxyTcpClient(hostname, port, proxyIp, proxyPort, null, null);
var sslStream = new SslStream(tcpClient.GetStream());
sslStream.AuthenticateAsClient(hostname);
client.Connect(tcpClient.GetStream());
public static TcpClient ProxyTcpClient(string targetHost, int targetPort, string httpProxyHost, int httpProxyPort, string proxyUserName, string proxyPassword)
const BindingFlags Flags = BindingFlags.NonPublic | BindingFlags.Instance;
Uri proxyUri = new UriBuilder
Scheme = Uri.UriSchemeHttp,
Uri targetUri = new UriBuilder
Scheme = Uri.UriSchemeHttp,
WebProxy webProxy = new WebProxy(proxyUri, true);
webProxy.Credentials = new NetworkCredential(proxyUserName, proxyPassword);
WebRequest request = WebRequest.Create(targetUri);
request.Proxy = webProxy;
request.Method = "CONNECT";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
Type responseType = responseStream.GetType();
PropertyInfo connectionProperty = responseType.GetProperty("Connection", Flags);
var connection = connectionProperty.GetValue(responseStream, null);
Type connectionType = connection.GetType();
PropertyInfo networkStreamProperty = connectionType.GetProperty("NetworkStream", Flags);
NetworkStream networkStream = (NetworkStream)networkStreamProperty.GetValue(connection, null);
Type nsType = networkStream.GetType();
PropertyInfo socketProperty = nsType.GetProperty("Socket", Flags);
Socket socket = (Socket)socketProperty.GetValue(networkStream, null);
return new TcpClient { Client = socket };