HTTP proxy | Blog | Limilabs https://www.limilabs.com/blog Using Limilabs .net components Wed, 26 Jun 2013 07:39:44 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 Imap, Pop3 or Smtp via HTTP or SOCKS proxy https://www.limilabs.com/blog/imap-pop3-smtp-via-http-socks-proxy https://www.limilabs.com/blog/imap-pop3-smtp-via-http-socks-proxy#comments Tue, 15 Feb 2011 12:33:05 +0000 http://www.limilabs.com/blog/?p=1704 Mail.dll (IMAP, POP3 and SMTP component for .NET) supports following proxy protocols: HTTP SOCKS5 SOCKS4a SOCKS4 As a prerequisite you need to add reference to Mail.dll and Proxy.dll libraries in your project. You can find both assemblies in the Mail.dll .NET email component download package. You can also find both assemblies on the .NET tab […]

The post Imap, Pop3 or Smtp via HTTP or SOCKS proxy first appeared on Blog | Limilabs.

]]>
Mail.dll (IMAP, POP3 and SMTP component for .NET) supports following proxy protocols:

  • HTTP
  • SOCKS5
  • SOCKS4a
  • SOCKS4

As a prerequisite you need to add reference to Mail.dll and Proxy.dll libraries in your project. You can find both assemblies in the Mail.dll .NET email component download package. You can also find both assemblies on the .NET tab in Visual Studio’s “Add reference” dialog after installation.

Following sample uses HTTP proxy to access IMAP server:

  1. First it creates proxy with specified type (ProxyType), proxy address and port using proxy factory
  2. Then it connects to IMAP, POP3 or SMTP server via proxy and creates a socket
  3. Finally it attaches socket to IMAP, POP3 or SMTP client
// C# version

ProxyFactory factory = new ProxyFactory();
IProxyClient proxy = factory.CreateProxy(ProxyType.Http, "221.3.154.9", 80);

Socket socket = proxy.Connect("imap.example.org", Imap.DefaultPort);

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

    // regular imap code

    imap.Close();
}

' VB.NET version

Dim factory As New ProxyFactory()
Dim proxy As IProxyClient = factory.CreateProxy(ProxyType.Http, "221.3.154.9", 80)

Dim socket As Socket = proxy.Connect("imap.example.org", Imap.DefaultPort)

Using imap As New Imap()
   imap.Attach(socket)

   ' regular imap code

   imap.Close()
End Using

Following sample uses HTTP proxy to access IMAP server over SSL connection. Note that we need to pass IMAP server name again to AttachSSL method for SSL authentication. Please also note that Imap.DefaultSSLPort constant is used.

// C# version

ProxyFactory factory = new ProxyFactory();
IProxyClient proxy = factory.CreateProxy(
   ProxyType.Http, "221.3.154.9", 80);

Socket socket = proxy.Connect("imap.gmail.com", Imap.DefaultSSLPort);

using (Imap imap = new Imap())
{
    imap.AttachSSL(socket, "imap.gmail.com");

    // regular imap code

    imap.Close();
}

' VB.NET version

Dim factory As New ProxyFactory()
Dim proxy As IProxyClient = factory.CreateProxy( _
   ProxyType.Http, "221.3.154.9", 80)

Dim socket As Socket = proxy.Connect("imap.gmail.com", Imap.DefaultSSLPort)

Using imap As New Imap()
   imap.AttachSSL(socket, "imap.gmail.com")

   ' regular imap code

   imap.Close()
End Using

The same code works for Smtp and Pop3 clients: you only need to use different port (Smtp.DefaultPort, Smtp.DefaultSSLPort, Pop3.DefaultPort, Pop3.DefaultSSLPort or any other port your server uses) when creating the proxy, and create appropriate client in ‘using’ line.

The post Imap, Pop3 or Smtp via HTTP or SOCKS proxy first appeared on Blog | Limilabs.

]]>
https://www.limilabs.com/blog/imap-pop3-smtp-via-http-socks-proxy/feed 23