Email Library for C# and VB.NET applications

GemBox.Email is a C# / VB.NET library that provides an easy and high-performance way for creating, sending, receiving, and processing emails in .NET Framework. GemBox.Email supports the SMTP, POP, and IMAP protocols so you can use it for connecting to all major email providers. It also supports loading and saving emails in MSG, EML, and MHTML formats, so you can store your emails exactly as they were received from the email server, with all of their headers and attachments.

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

Notice that on the right side you have GemBox.Email Examples section with which you can navigate through examples and explore supported features.

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.

1using GemBox.Email;
2using GemBox.Email.Pop;
3using System;
4
5class Sample
6{
7    [STAThread]
8    static void Main(string[] args)
9    {
10        // If using Professional version, put your serial key below.
11        ComponentInfo.SetLicense("FREE-LIMITED-KEY");
12
13        using (PopClient pop = new PopClient("<ADDRESS> (e.g. pop.gmail.com)"))
14        {
15            // Connect and login
16            pop.Connect();
17            Console.WriteLine("Connected.");
18
19            pop.Authenticate("<USERNAME>", "<PASSWORD>");
20            Console.WriteLine("Authenticated.");
21
22            // Check if there are any messages available on the server
23            if (pop.GetCount() == 0)
24                return;
25
26            // Download message with sequence number 1 (first one)
27            MailMessage message = pop.GetMessage(1);
28
29            // Display message sender and subject
30            Console.WriteLine("From: " + message.From.ToString());
31            Console.WriteLine("Subject: " + message.Subject);
32
33            // Write message body
34            Console.WriteLine("Body:");
35
36            string text;
37
38            if (message.BodyHtml != null)
39                text = message.BodyHtml;
40            else
41                text = message.BodyText;
42
43            foreach (string line in text.Split(new string[] { "\r\n" }, StringSplitOptions.None))
44                Console.WriteLine(' ' + line);
45
46        }
47    }
48}
1Imports GemBox.Email
2Imports GemBox.Email.Pop
3
4Module Samples
5
6    Sub Main()
7
8        ' If using Professional version, put your serial key below.
9        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
10
11        Using pop As New PopClient("<ADDRESS> (e.g. pop.gmail.com)")
12
13            ' Connect and login
14            pop.Connect()
15            Console.WriteLine("Connected.")
16
17            pop.Authenticate("<USERNAME>", "<PASSWORD>")
18            Console.WriteLine("Authenticated.")
19
20            ' Check if there are any messages available on the server
21            If pop.GetCount() = 0 Then Exit Sub
22
23            ' Download message with sequence number 1 (first one)
24            Dim message As MailMessage = pop.GetMessage(1)
25
26            'Display message sender and subject
27            Console.WriteLine("From: " & message.From.ToString())
28            Console.WriteLine("Subject: " & message.Subject)
29
30            ' Write message body
31            Console.WriteLine("Body:")
32
33            Dim text As String
34
35            If message.BodyHtml IsNot Nothing Then
36                text = message.BodyHtml
37            Else
38                text = message.BodyText
39            End If
40
41            For Each line As String In text.Split(New String() {vbCrLf}, StringSplitOptions.None)
42                Console.WriteLine(" "c & line)
43            Next
44
45        End Using
46
47    End Sub
48
49End Module

Check next sample or find out more about GemBox.Email and GemBox Software.