More .NET libraries
-
Rebex Mail Pack
IMAP, MS Graph, EWS, POP3, SMTP, MIME, S/MIME, MSG
-
Rebex Total Pack
All Rebex .NET libraries together
Back to feature list...
Advanced features
On this page:
UIDPLUS extension
Most modern IMAP servers implement the UIDPLUS extension
This extension makes it possible to retrieve unique IDs of newly created messages when using
CopyMessage
, StoreMessage
and StoreRawMessage
methods.
// create IMAP client instance, connect, log in using (var imap = new Rebex.Net.Imap()) { imap.Connect(hostname, SslMode.Implicit); imap.Login(username, password); // upload a message to "Inbox" folder // Unique ID assigned to the message is returned by the method if supported by the server string uniqueId = imap.StoreMessage("Inbox", mail); // check whether UIDPLUS is supported and enabled if ((imap.SupportedExtensions & imap.EnabledExtensions & ImapExtensions.UniqueIdPlus) == ImapExtensions.UniqueIdPlus) { Console.WriteLine("Message ID: {0}", uniqueId); } }
' create IMAP client instance, connect, log in Dim imap As New Rebex.Net.Imap() imap.Connect(hostname, SslMode.Implicit) imap.Login(username, password) ' upload a message to "Inbox" folder ' Unique ID assigned to the message is returned by the method if supported by the server Dim uniqueId As String = imap.StoreMessage("Inbox", mail) ' check whether UIDPLUS is supported and enabled If (imap.SupportedExtensions And imap.EnabledExtensions And ImapExtensions.UniqueIdPlus) = ImapExtensions.UniqueIdPlus Then Console.WriteLine("Message ID: {0}", uniqueId) End If
Custom commands
The Imap
object can execute custom commands, which makes it
possible to utilize functionality not yet covered by Rebex API.
To send a custom command use the Imap.SendCommand
method.
To read the response of this command use the Imap.ReadResponse
method.
The following code uses SendCommand
/ReadResonse
methods to retrive Inbox quotas (if supported by the server):
// create IMAP client instance, connect, log in // ... // determine Inbox quotas imap.SendCommand("GETQUOTAROOT", "Inbox"); ImapResponse response = imap.ReadResponse(); // check the response code if (response.Code != ImapResponseCode.Ok) { Console.WriteLine("Command not understood."); } else { // display Inbox quotas returned by the server foreach (ImapResponseLine line in response.GetLines()) { if (line.Code == "QUOTA") { // Format: quote_root_name (resource_name current_usage limit) // Sample: "" (STORAGE 546615 7599416) Console.WriteLine(line.Parameters); } } }
' create IMAP client instance, connect, log in ' ... ' determine Inbox quotas imap.SendCommand("GETQUOTAROOT", "Inbox") Dim response As ImapResponse = imap.ReadResponse() ' check the response code If response.Code <> ImapResponseCode.Ok Then Console.WriteLine("Command not understood.") Else ' display Inbox quotas returned by the server For Each line As ImapResponseLine In response.GetLines() If line.Code = "QUOTA" Then ' Format: quote_root_name (resource_name current_usage limit) ' Sample: "" (STORAGE 546615 7599416) Console.WriteLine(line.Parameters) End If Next End If
Fine-tuning IMAP behavior
Imap
objects makes it possible to specify various low-level settings
and workarounds.
Working with IMAP extensions
IMAP protocol offers lots of extensions.
To determine which extensions are supported by your IMAP server, use the Imap.SupportedExtensions
property.
By default, all supported extensions except Compression
.
To enable or disable some extensions, use the Imap.EnabledExtensions
property.
// create IMAP client instance and connect // ... // does the server support IDLE command? bool idleSupported = (imap.SupportedExtensions & ImapExtensions.Idle) == ImapExtensions.Idle; // disable UIDPLUS extension imap.EnabledExtensions &= ~ImapExtensions.UniqueIdPlus;
' create IMAP client instance and connect ' ... ' does the server support IDLE command? Dim idleSupported As Boolean = (imap.SupportedExtensions And ImapExtensions.Idle) = ImapExtensions.Idle ' disable UIDPLUS extension imap.EnabledExtensions = imap.EnabledExtensions And Not ImapExtensions.UniqueIdPlus
Connecting to Exchange shared mailboxes
To connect to a shared mailbox on Microsoft Exchange Server, use the following form of the Login
method:
// create IMAP client instance, connect // ... // authenticate to a shared mailbox imap.Login("Domain/Username/AliasOfSharedMailbox", password); // or use it like this (equivalent to above) imap.Login("Username@Domain/AliasOfSharedMailbox", password);
' create IMAP client instance, connect ' ... ' authenticate to a shared mailbox imap.Login("Domain/Username/AliasOfSharedMailbox", password) ' or use it like this (equivalent to above) imap.Login("Username@Domain/AliasOfSharedMailbox", password)
Back to feature list...