GemBox.Email is a .NET component that enables you to read, write, receive, and send emails from your .NET applications using one simple API.

Folders

IMAP holds messages in a folder-like structure, so a folder needs to be selected before any message operations can be executed. Folders, called labels by some providers, can be created, renamed, and removed by users.

The example shows how to list all the folders on a server using the GemBox.Email component, and how to create, rename, and remove a custom folder.

Screenshot
Folders Screenshot

See the full code below.

using GemBox.Email;
using GemBox.Email.Imap;
using GemBox.Email.Mime;
using GemBox.Email.Security;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        using (ImapClient imap = new ImapClient("<ADDRESS> (e.g. imap.gmail.com)"))
        {
            imap.Connect();
            Console.WriteLine("Connected.");

            imap.Authenticate("<USERNAME>", "<PASSWORD>");
            Console.WriteLine("Authenticated.");

            // List all folders on the server
            IList<ImapFolderInfo> folders = imap.ListFolders();

            Console.WriteLine("Listing folders...");

            foreach (ImapFolderInfo info in folders)
                Console.WriteLine(" {0,18}: {1}", info.Name, string.Join(", ", info.Flags));

            // Create new folder and list all folders again
            imap.CreateFolder("GemBox");

            Console.WriteLine("Listing folders again...");

            folders = imap.ListFolders();
            foreach (ImapFolderInfo info in folders)
                Console.WriteLine(" {0,18}: {1}", info.Name, string.Join(", ", info.Flags));

            // Delete newly created folder and repeat listing
            imap.DeleteFolder("GemBox");

            Console.WriteLine("Final folder listing...");

            folders = imap.ListFolders();
            foreach (ImapFolderInfo info in folders)
                Console.WriteLine(" {0,18}: {1}", info.Name, string.Join(", ", info.Flags));
        }
    }
}
Imports System.Globalization
Imports System.Net.Security
Imports System.Security.Cryptography.X509Certificates
Imports GemBox.Email
Imports GemBox.Email.Imap
Imports GemBox.Email.Mime

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Using imap As New ImapClient("<ADDRESS> (e.g. imap.gmail.com)")

            imap.Connect()
            Console.WriteLine("Connected.")

            imap.Authenticate("<USERNAME>", "<PASSWORD>")
            Console.WriteLine("Authenticated.")

            ' List all folders on the server
            Dim folders As IList(Of ImapFolderInfo) = imap.ListFolders()

            Console.WriteLine("Listing folders...")

            For Each info As ImapFolderInfo In folders
                Console.WriteLine(" {0,18}: {1}", info.Name, String.Join(", ", info.Flags))
            Next

            ' Create new folder and list all folders again
            imap.CreateFolder("GemBox")

            Console.WriteLine("Listing folders again...")

            folders = imap.ListFolders()
            For Each info As ImapFolderInfo In folders
                Console.WriteLine(" {0,18}: {1}", info.Name, String.Join(", ", info.Flags))
            Next

            ' Delete newly created folder and repeat listing
            imap.DeleteFolder("GemBox")

            Console.WriteLine("Final folder listing...")

            folders = imap.ListFolders()
            For Each info As ImapFolderInfo In folders
                Console.WriteLine(" {0,18}: {1}", info.Name, String.Join(", ", info.Flags))
            Next

        End Using

    End Sub

End Module

Check next sample.