Email Library for C# and VB.NET applications

The fastest way how you can get started with GemBox.Email library is by exploring our collection of C# and VB.NET examples. These are live examples that demonstrate various supported features in GemBox.Email.

System Requirements

GemBox.Email requires only the .NET Framework version 3.0 or above.

Hello World

The following example shows some basic features, like how to instance a POP client, connect and authenticate, check for new messages, and save the first one to a hard disk.

Screenshot
Hello World Screenshot

See the full code below.

using GemBox.Email;
using GemBox.Email.Pop;
using System;

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

        using (PopClient pop = new PopClient("<ADDRESS> (e.g. pop.gmail.com)"))
        {
            // Connect and login
            pop.Connect();
            Console.WriteLine("Connected.");

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

            // Check if there are any messages available on the server
            if (pop.GetCount() == 0)
                return;

            // Download message with sequence number 1 (first one)
            MailMessage message = pop.GetMessage(1);

            // Display message sender and subject
            Console.WriteLine("From: " + message.From.ToString());
            Console.WriteLine("Subject: " + message.Subject);

            // Write message body
            Console.WriteLine("Body:");

            string text;

            if (message.BodyHtml != null)
                text = message.BodyHtml;
            else
                text = message.BodyText;

            foreach (string line in text.Split(new string[] { "\r\n" }, StringSplitOptions.None))
                Console.WriteLine(' ' + line);

        }
    }
}
Imports GemBox.Email
Imports GemBox.Email.Pop

Module Samples

    Sub Main()

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

        Using pop As New PopClient("<ADDRESS> (e.g. pop.gmail.com)")

            ' Connect and login
            pop.Connect()
            Console.WriteLine("Connected.")

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

            ' Check if there are any messages available on the server
            If pop.GetCount() = 0 Then Exit Sub

            ' Download message with sequence number 1 (first one)
            Dim message As MailMessage = pop.GetMessage(1)

            'Display message sender and subject
            Console.WriteLine("From: " & message.From.ToString())
            Console.WriteLine("Subject: " & message.Subject)

            ' Write message body
            Console.WriteLine("Body:")

            Dim text As String

            If message.BodyHtml IsNot Nothing Then
                text = message.BodyHtml
            Else
                text = message.BodyText
            End If

            For Each line As String In text.Split(New String() {vbCrLf}, StringSplitOptions.None)
                Console.WriteLine(" "c & line)
            Next

        End Using

    End Sub

End Module

Check next sample.