ComponentPro UltimateMail

      Connecting through a proxy server

      Language Filter: AllSend comments on this topic to ComponentPro

      The Ultimate IMAP component fully supports many proxy servers (often referred to as "proxies"). If you need to connect to your IMAP server through a proxy, simply create a new instance of the WebProxyEx class, set the appropriate properties of the WebProxyEx object, assign it to the Proxy property of the Imap class and the necessary proxy communication will take place.

      Ultimate IMAP component supports the following Proxy servers:

      Proxy Type Information
      SOCKS4 SOCKS4 proxy.
      SOCKS4A SOCKS4A proxy (capable of resolving domain names).
      SOCKS5 SOCKS5 proxy.
      HTTP CONNECT (Basic and NTLM supported) HTTP proxy using CONNECT method.

      The following steps will help you to connect to an IMAP server through a proxy server:

      Connecting through a proxy server

      1. Add using directives to your code to create aliases for existing namespaces and avoid having to type the fully qualified type names. The code looks similar to the following:
        using System;
        using ComponentPro.Net;
        using ComponentPro.Net.Mail;
        
      2. Create a new instance of the Imap class.
      3. Create a new instance of the WebProxyEx class, set the appropriate properties of the WebProxyEx object and assign it to the Proxy property of the Imap class.
      4. Now you can connect to the IMAP server with Connect methods. The code looks similar to the following:
        // Create a new instance.
        Imap client = new Imap();
        
        // Create a new proxy object.
        WebProxyEx proxy = new WebProxyEx();
        proxy.Server = "proxyserver"; // Set proxy address here.
        proxy.Port = 1080; // Set proxy port here.
        proxy.UserName = "username"; // Proxy user name.
        proxy.Password = "password"; // Password.
        
        client.Proxy = proxy;
        
        // Connect to the IMAP server.
        client.Connect("myserver");
        
      5. Use your user name and password to login with Authenticate methods.  The code looks similar to the following:
        // Authenticate.
        client.Authenticate("userName", "password");
        
      6. Do your work like selecting a mailbox, displaying unique id of messages, etc.  The code looks similar to the following:
        // Do something here... 
        // ... 
         
        // Select INBOX mailbox.
        client.Select("INBOX");
        // Print out unique id of all messages. 
        foreach (ImapMessage msg in client.ListMessages(ImapEnvelopeParts.UniqueId))
        {
            Console.WriteLine(msg.UniqueId);
        }
        
      7. After completing your work, call the Disconnect method to close the IMAP session. 

      Final example code

      using System;
      using ComponentPro.Net;
      using ComponentPro.Net.Mail;
      
      ...
      
      // Create a new instance.
      Imap client = new Imap();
      
      // Create a new proxy object.
      WebProxyEx proxy = new WebProxyEx();
      proxy.Server = "proxyserver"; // Set proxy address here.
      proxy.Port = 1080; // Set proxy port here.
      proxy.UserName = "username"; // Proxy user name.
      proxy.Password = "password"; // Password.
      
      client.Proxy = proxy;
      
      // Connect to the IMAP server.
      client.Connect("myserver");
      
      // Authenticate.
      client.Authenticate("userName", "password");
      
      // Do something here... 
      // ... 
       
      // Select INBOX mailbox.
      client.Select("INBOX");
      // Print out unique id of all messages. 
      foreach (ImapMessage msg in client.ListMessages(ImapEnvelopeParts.UniqueId))
      {
          Console.WriteLine(msg.UniqueId);
      }
      
      // Disconnect.
      client.Disconnect();