Load and Save a Mbox Message Collection

GemBox.Email provides an advanced API for working with the Mbox (Mboxrd) file format, allowing you to load, modify and save email in C# and VB.NET, as shown in the example below.

Upload your file (Drag file here)
using GemBox.Email;
using System;

class Program
{
    static void Main()
    {
        // If using the Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        // Load message collection.
        MailMessageCollection messages = MailMessageCollection.Load("%InputFileName%");

        // Display message information.
        foreach (MailMessage message in messages)
        {
            Console.WriteLine($"From: {message.From}");
            Console.WriteLine($"Subject: {message.Subject}");
            Console.WriteLine($"Body: {message.BodyText}");
            Console.WriteLine();
        }

        // Create new message.
        MailMessage newMessage = new MailMessage("sender@example.com", "receiver@example.com")
        {
            Subject = "Test email message with a text body",
            BodyText = "This is a test message with a text body."
        };

        // Add message to collection.
        messages.Add(newMessage);

        // Save message collection.
        messages.Save("Modified Collection.mbox");
    }
}
Imports GemBox.Email
Imports System

Module Program

    Sub Main()

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

        ' Load message collection.
        Dim messages As MailMessageCollection = MailMessageCollection.Load("%InputFileName%")

        ' Display message information.
        For Each message As MailMessage In messages
            Console.WriteLine($"From: {message.From}")
            Console.WriteLine($"Subject: {message.Subject}")
            Console.WriteLine($"Body: {message.BodyText}")
            Console.WriteLine()
        Next

        ' Create new message.
        Dim newMessage As New MailMessage("sender@example.com", "receiver@example.com") With
        {
            .Subject = "Test email message with a text body",
            .BodyText = "This is a test message with a text body."
        }

        ' Add message to the collection
        messages.Add(newMessage)

        ' Save message collection
        messages.Save("Modified Collection.mbox")

    End Sub
End Module
Working with MBox files in C# and VB.NET
Screenshot of loaded emails from MBox collection

Besides basic features like loading (via MailMessageCollection.Load methods), modifying and saving (via MailMessageCollection.Save methods), you can use different loading methods, which speeds up the process.

For example, you can use MailMessageCollection.LazyLoad for lazy message iteration or MailMessageCollection.LoadHeaders for reading just message headers.

See also


Next steps

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

Download Buy