Email Library for C# and VB.NET Applications

The fastest way to get started with the GemBox.Email library is by exploring our collection of C# and VB.NET examples. These are live examples that demonstrate supported features and APIs for achieving various email-related tasks with the GemBox.Email component.

System Requirements

GemBox.Email works on .NET Framework 3.5 or higher and platforms that implement .NET Standard 2.0 or higher. It doesn't have any other dependency.

Hello World

The first step in using the GemBox.Email library is to add a reference to GemBox.Email.dll in your C# or VB.NET project. There are three ways how to do that.

a) Add from NuGet:

You can add GemBox.Email as a package by using the following command from the NuGet Package Manager Console: Install-Package GemBox.Email

Or you can search and add GemBox.Email from the NuGet Package Manager.

Adding GemBox.Email library from NuGet

b) Or add from Setup:

You can download the GemBox.Email Setup from this page. After installing the setup, you can add a reference to GemBox.Email.dll from the Global Assembly Cache (GAC).

Adding GemBox.Email library from GAC

c) Or add from DLL file:

You can download GemBox.Email.dll file from this page and add a reference by browsing to it.

Adding GemBox.Email library from DLL

The second step is to add a directive for the GemBox.Email namespace.
For a C# project, use: using GemBox.Email;
For a VB.NET project, use: Import GemBox.Email

The third step is to set the license key to use GemBox.Email in one of its working modes.
To use a Free mode in a C# project, use: ComponentInfo.SetLicense("FREE-LIMITED-KEY");
To use a Free mode in a VB.NET project, use: ComponentInfo.SetLicense("FREE-LIMITED-KEY")
You can read more about GemBox.Email's working modes on the Evaluation and Licensing help page.

The last step is to write your application-specific email code, like the following example code that shows how to connect to your email server and download a mail message from it.

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

class Program
{
    static void Main()
    {
        // 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 (the first message).
            MailMessage message = pop.GetMessage(1);

            // Display message sender and subject.
            Console.WriteLine();
            Console.WriteLine($"From: {message.From}");
            Console.WriteLine($"Subject: {message.Subject}");

            // Display message body.
            Console.WriteLine("Body:");
            string body = string.IsNullOrEmpty(message.BodyHtml) ?
                message.BodyText :
                message.BodyHtml;
            Console.WriteLine(body);
        }
    }
}
Imports System
Imports GemBox.Email
Imports GemBox.Email.Pop

Module Program

    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 (the first message).
            Dim message As MailMessage = pop.GetMessage(1)

            ' Display message sender and subject.
            Console.WriteLine()
            Console.WriteLine($"From: {message.From}")
            Console.WriteLine($"Subject: {message.Subject}")

            ' Display message body.
            Console.WriteLine("Body:")
            Dim body As String = If(String.IsNullOrEmpty(message.BodyHtml),
                message.BodyText,
                message.BodyHtml)
            Console.WriteLine(body)

        End Using

    End Sub

End Module
Screenshot of basic Hello World output
Using GemBox.Email library in C# and VB.NET

Check next example or download examples from GitHub.