IMAP Email Client connection in C# and VB.NET

The Internet Message Access Protocol (IMAP) is currently the most used protocol for managing an email box by multiple clients or devices. It has replaced the older POP protocol due to its advanced features, which include, but are not limited to, folders, flags and search support, and asynchronous updates by IDLE extension.

The GemBox.Email .NET component supports the latest version (version 4 revision 1; IMAP4rev1) and the following example demonstrates how to connect and authenticate with a mail server using the ImapClient class in C# and VB.NET.

Screenshot
Connect with IMAP client 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)"))
        {
            // Connect to mail server
            imap.Connect();
            Console.WriteLine("Connected.");

            // Authenticate with specified username and password 
            // (ImapClient will use strongest possible authentication mechanism)
            imap.Authenticate("<USERNAME>", "<PASSWORD>");
            Console.WriteLine("Authenticated.");
        }
    }
}
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)")

            ' Connect to mail server
            imap.Connect()
            Console.WriteLine("Connected.")

            ' Authenticate with specified username and password
            ' (ImapClient will use strongest possible authentication mechanism)
            imap.Authenticate("<USERNAME>", "<PASSWORD>")
            Console.WriteLine("Authenticated.")

        End Using

    End Sub

End Module