Spire.Email supports to manage folder subscriptions by using ImapClient.Subscribe and ImapClient.Unsubscribe method.
The following example shows how to subscribe to a folder and unsubscribe from a folder using Spire.Email component.
Detail steps:
Step 1: Create an ImapClient instance.
ImapClient imap = new ImapClient();
Step 2: Set host, port, authentication and connection protocol.
imap.Host = "outlook.office365.com"; imap.Port = 143; imap.Username = "LeonDavisLD@outlook.com"; imap.Password = "password"; imap.ConnectionProtocols = ConnectionProtocols.Ssl;
Step 3: Connect the imap server.
imap.Connect();
Step 4: Subscribe folder using its name.
imap.Subscribe("Folder1");
Step 5: Unsubscribe folder.
imap.Unsubscribe("Folder2");
Screenshot:
Full code:
[C#]
using Spire.Email; using Spire.Email.IMap; namespace SubscribAndUnsubscribeFolders { class Program { static void Main(string[] args) { //Create an ImapClient instance ImapClient imap = new ImapClient(); //Set host, port, authentication and connection protocol imap.Host = "outlook.office365.com"; imap.Port = 143; imap.Username = "LeonDavisLD@outlook.com"; imap.Password = "password"; imap.ConnectionProtocols = ConnectionProtocols.Ssl; //Connect the imap server imap.Connect(); //subscribe folder using its name imap.Subscribe("Folder1"); //Unsubscribe folder imap.Unsubscribe("Folder2"); } } }
[VB.NET]
Imports Spire.Email Imports Spire.Email.IMap Namespace SubscribAndUnsubscribeFolders Class Program Private Shared Sub Main(args As String()) 'Create an ImapClient instance Dim imap As New ImapClient() 'Set host, port, authentication and connection protocol imap.Host = "outlook.office365.com" imap.Port = 143 imap.Username = "LeonDavisLD@outlook.com" imap.Password = "password" imap.ConnectionProtocols = ConnectionProtocols.Ssl 'Connect the imap server imap.Connect() 'subscribe folder using its name imap.Subscribe("Folder1") 'Unsubscribe folder imap.Unsubscribe("Folder2") End Sub End Class End Namespace