Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Email .NET
>
Tutorial
> List folders
This example shows you how to login to IMAP server and list folders.
C# example
using System; using Independentsoft.Email; using Independentsoft.Email.Imap; namespace Sample { class Program { static void Main(string[] args) { ImapClient client = new ImapClient("myserver"); client.Connect(); client.Login("username", "password"); //List all folders and their subfolders Folder[] folders = client.GetFolders(); for (int i = 0; i < folders.Length; i++) { Console.WriteLine("Name=" + folders[i].Name + ", Path=" + folders[i].Path); } Console.WriteLine("-------------------------------------------"); //List all folders which name starts with "Test" and their subfolders folders = client.GetFolders("Test*"); for (int i = 0; i < folders.Length; i++) { Console.WriteLine("Name=" + folders[i].Name + ", Path=" + folders[i].Path); } Console.WriteLine("-------------------------------------------"); //List all folders from Inbox folder and their subfolders folders = client.GetFolders("Inbox/", "*"); for (int i = 0; i < folders.Length; i++) { Console.WriteLine("Name=" + folders[i].Name + ", Path=" + folders[i].Path); } Console.WriteLine("-------------------------------------------"); //List all folders from the Inbox folder which name starts with "myfolder" but not their subfolders folders = client.GetFolders("Inbox/", "myfolder%"); for (int i = 0; i < folders.Length; i++) { Console.WriteLine("Name=" + folders[i].Name + ", Path=" + folders[i].Path); } Console.WriteLine("-------------------------------------------"); client.Disconnect(); Console.WriteLine("Press ENTER to exit!"); Console.Read(); } } }
VB example
Imports System Imports Independentsoft.Email Imports Independentsoft.Email.Imap Namespace Sample Class Program Shared Sub Main(ByVal args As String()) Dim client As New ImapClient("myserver") client.Connect() client.Login("username", "password") 'List all folders and their subfolders Dim folders As Folder() = client.GetFolders() For i As Integer = 0 To folders.Length - 1 Console.WriteLine(("Name=" & folders(i).Name & ", Path=") + folders(i).Path) Next Console.WriteLine("-------------------------------------------") 'List all folders which name starts with "Test" and their subfolders folders = client.GetFolders("Test*") For i As Integer = 0 To folders.Length - 1 Console.WriteLine(("Name=" & folders(i).Name & ", Path=") + folders(i).Path) Next Console.WriteLine("-------------------------------------------") 'List all folders from Inbox folder and their subfolders folders = client.GetFolders("Inbox/", "*") For i As Integer = 0 To folders.Length - 1 Console.WriteLine(("Name=" & folders(i).Name & ", Path=") + folders(i).Path) Next Console.WriteLine("-------------------------------------------") 'List all folders from the Inbox folder which name starts with "myfolder" but not their subfolders folders = client.GetFolders("Inbox/", "myfolder%") For i As Integer = 0 To folders.Length - 1 Console.WriteLine(("Name=" & folders(i).Name & ", Path=") + folders(i).Path) Next Console.WriteLine("-------------------------------------------") client.Disconnect() Console.WriteLine("Press ENTER to exit!") Console.Read() End Sub End Class End Namespace