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
- 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;
Imports ComponentPro.Net
Imports ComponentPro.Net.Mail
- Create a new instance of the Imap class.
- 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.
- 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");
' Create a new instance.
Dim client As New Imap()
' Create a new proxy object.
Dim proxy As 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")
- Use your user name and password to login with Authenticate methods. The code looks similar to the following:
// Authenticate.
client.Authenticate("userName", "password");
' Authenticate.
client.Authenticate("userName", "password")
- 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);
}
' Do something here...
' ...
' Select INBOX mailbox.
client.Select("INBOX")
' Print out unique id of all messages.
For Each msg As ImapMessage In client.ListMessages(ImapEnvelopeParts.UniqueId)
Console.WriteLine(msg.UniqueId)
Next msg
- 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();
Imports ComponentPro.Net
Imports ComponentPro.Net.Mail
...
' Create a new instance.
Dim client As New Imap()
' Create a new proxy object.
Dim proxy As 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.
For Each msg As ImapMessage In client.ListMessages(ImapEnvelopeParts.UniqueId)
Console.WriteLine(msg.UniqueId)
Next msg
' Disconnect.
client.Disconnect()