You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am exceptionally on a network that requires a proxy configuration.
I thought I would try out my email software on this network, and as it turns out the TcpClient object doesn't work on proxies and doesn't seem to allow any proxy configuration.
As an example, the connect method in Imap client could become something like :
public void Connect(string hostname, int port, bool ssl, string proxyHost = null, int proxyPort = -1, ProxyType proxyType = ProxyType.None)
{
try
{
Host = hostname;
Port = port;
Ssl = ssl;
if (proxyHost != null && proxyType != ProxyType.None && proxyPort > -1)
{
// create an instance of the client proxy factory
ProxyClientFactory factory = new ProxyClientFactory();
// use the proxy client factory to generically specify the type of proxy to create
// the proxy factory method CreateProxyClient returns an IProxyClient object
IProxyClient proxy = factory.CreateProxyClient(proxyType, proxyHost, proxyPort);
// create a connection through the proxy to hostname over the port
_Connection = proxy.CreateConnection(hostname, port);
}
else { _Connection = new TcpClient(hostname, port); }
_Stream = _Connection.GetStream();
if (ssl)
{
var sslSream = new System.Net.Security.SslStream(_Stream);
_Stream = sslSream;
sslSream.AuthenticateAsClient(hostname);
}
_Reader = new StreamReader(_Stream, System.Text.Encoding.Default);
string info = _Reader.ReadLine();
OnConnected(info);
IsConnected = true;
Host = hostname;
}
catch (Exception)
{
IsConnected = false;
throw;
}
}
Hi JackEker,
I'm really sorry for the (super) late reply, the project in wich I was using the library is now over.
Actually when I wrote this post I was hoping that someone else would be interested in the matter because my attempts to implement this functionnality weren't succesful :/
I think the general idea is there but more work would need to be done with the starksoft library which is supposed to work.
I hope that this wasn't a key functionnality in your project...
Hello,
I am exceptionally on a network that requires a proxy configuration.
I thought I would try out my email software on this network, and as it turns out the TcpClient object doesn't work on proxies and doesn't seem to allow any proxy configuration.
Have you used your library through a proxy ?
If not, i have found a quite simple open-source C# library creating TcpClient objects through proxies :
http://www.starksoft.com/prod_proxy.html
As an example, the connect method in Imap client could become something like :
public void Connect(string hostname, int port, bool ssl, string proxyHost = null, int proxyPort = -1, ProxyType proxyType = ProxyType.None)
{
try
{
Host = hostname;
Port = port;
Ssl = ssl;
and the imap constructor :
public ImapClient(string host, string username, string password, AuthMethods method = AuthMethods.Login, int port = 143, bool secure = false, string proxyHost = null, int proxyPort = -1, ProxyType proxyType = ProxyType.None) {
Connect(host, port, secure, proxyHost, proxyPort, proxyType);
AuthMethod = method;
Login(username, password);
}
The text was updated successfully, but these errors were encountered: