Monday, 31 July 2017 08:04

Subscribe and Unsubscribe Folders in C#, VB.NET

Written by  support iceblue
Rate this item
(0 votes)

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:

Subscribe and Unsubscribe Folders in C#, VB.NET

Full code:

[C#]
//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]
'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")

Additional Info

  • tutorial_title: