Meziantou.Framework.Email 1.0.0

Prefix Reserved
dotnet add package Meziantou.Framework.Email --version 1.0.0
                    
NuGet\Install-Package Meziantou.Framework.Email -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Meziantou.Framework.Email" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Meziantou.Framework.Email" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Meziantou.Framework.Email" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Meziantou.Framework.Email --version 1.0.0
                    
#r "nuget: Meziantou.Framework.Email, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Meziantou.Framework.Email@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Meziantou.Framework.Email&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Meziantou.Framework.Email&version=1.0.0
                    
Install as a Cake Tool

Meziantou.Framework.Email

Reads and writes email files, without native dependencies. It does not send email. The types are in the namespaces Meziantou.Framework.Email (EmailMessage, MimeMessage), Meziantou.Framework.Email.Mapi (the Outlook items, .msg, TNEF), Meziantou.Framework.Email.Storage (PST, mbox, Maildir, Apple Mail, Thunderbird, offline address books), Meziantou.Framework.Email.Contacts (vCard) and Meziantou.Framework.Email.Calendar (iCalendar).

  • Outlook data files: PST and OST, in the ANSI, Unicode and 4K-page formats, with or without encryption (MS-PST). No Outlook or MAPI installation is needed.
  • Email messages (.eml): the Internet Message Format and MIME, with the encoded headers, the multiparts, the attachments and the embedded messages. A message read and written without changes keeps its bytes.
  • Outlook items (.msg, MS-OXMSG) and Outlook templates (.oft), read and written with the types of the items of Outlook data files.
  • TNEF streams (winmail.dat, MS-OXTNEF), read and written with the same types; the winmail.dat attachments of MIME messages are expanded when they are converted to EmailMessage.
  • Mailboxes: mbox files (mboxo, mboxrd, mboxcl, mboxcl2), Maildir folders, Apple Mail .emlx files, and the Mork databases of Thunderbird (.msf summaries).
  • Contacts and calendars: vCard 2.1, 3.0 and 4.0, iCalendar with its time zones and the occurrences of its recurrence rules, converted to and from the contacts, appointments and tasks of Outlook, and meeting invitations (iTIP, iMIP) converted to and from the meeting messages of Outlook.
  • Offline address books of Exchange and Outlook (udetails.oab, version 4 Full Details, MS-OXOAB).
  • EmailMessage, a model to convert a message from one format to another.
  • EmailFormatDetector, which detects the format of a file from its content.
  • MailboxConverter, which converts a mailbox with its folders between Outlook data files, mbox files (Thunderbird) and Maildir folders.
  • S/MIME: the signatures of signed messages are checked, and encrypted messages decrypted with the certificate of a recipient.

Outlook data files:

  • Folders, search folders and associated items
  • Emails: properties, recipients, bodies in plain text, HTML and RTF (compressed RTF, MS-OXRTFCP), and the HTML and text bodies encapsulated in RTF (MS-OXRTFEX)
  • Attachments, read block by block, and embedded messages
  • Contacts, distribution lists, appointments with their recurrence and exceptions, tasks, sticky notes and journal entries
  • Every MAPI property, including the named properties
  • A writer that creates new files, and copies items from other files
  • A validator that checks the structures of a file

Read a file

using var file = PstFile.Open(path);
var subjects = new List<string>();
void Visit(PstFolder folder)
{
    foreach (var item in folder.EnumerateItems())
    {
        subjects.Add($"{folder.Path}: {item.Subject}");
    }

    foreach (var child in folder.Folders)
    {
        Visit(child);
    }
}

Visit(file.RootFolder);
Assert.Contains("Top of Outlook data file/Inbox/tmp: original email", subjects);

Read the attachments

using var file = PstFile.Open(path);
var message = file.GetFolder("Inbox")!.EnumerateItems().First();
foreach (var attachment in message.Attachments)
{
    if (attachment.Method == MapiAttachmentMethod.ByValue)
    {
        // Read the content block by block, without loading it in memory
        using var content = attachment.OpenRead();
        using var output = File.Create(Path.Combine(directory.FullName, Path.GetFileName(attachment.Name ?? "attachment")));
        content.CopyTo(output);
    }
}

Write a file

using (var writer = PstWriter.Create(path, new PstWriterOptions { DisplayName = "Archive" }))
{
    var inbox = writer.RootFolder.CreateFolder("Inbox", "IPF.Note");
    var message = new MapiMessageBuilder
    {
        Subject = "Hello",
        Body = "Hello from Meziantou.Framework.Email",
        SenderName = "Alice",
        SenderEmailAddress = "alice@example.com",
        SenderAddressType = "SMTP",
        ClientSubmitTime = new DateTime(2026, 1, 15, 9, 0, 0, DateTimeKind.Utc),
    };
    message.Recipients.Add(new MapiRecipientBuilder("Bob", "bob@example.com"));
    message.Attachments.Add(MapiAttachmentBuilder.FromContent("notes.txt", "Some notes"u8.ToArray(), "text/plain"));
    inbox.AddItem(message);

    var contacts = writer.RootFolder.CreateFolder("Contacts", "IPF.Contact");
    contacts.AddItem(new MapiContactBuilder { GivenName = "Bob", Surname = "Smith", Email1Address = "bob@example.com" });
}

using var file = PstFile.Open(path);
var item = file.GetFolder("Inbox")!.EnumerateItems().Single();
Assert.Equal("Hello", item.Subject);
Assert.Equal("bob@example.com", item.Recipients.Single().EmailAddress);
Assert.Equal("notes.txt", item.Attachments.Single().Name);

Read an email message

var message = MimeMessage.Load(path);
Assert.Equal("Attachments", message.Subject);
Assert.Equal("alice@example.com", message.From[0].Address);
Assert.Equal("See the attachments.", message.TextBody?.TrimEnd());

foreach (var attachment in message.Attachments.OfType<MimePart>())
{
    // The file name is decoded (RFC 2047 and RFC 2231), and the content is decoded from base64 or quoted-printable
    var fileName = attachment.FileName;
    var content = attachment.GetContent();
    Assert.NotNull(content);
    _ = fileName;
}

Save an Outlook item as an .msg file

var message = new MapiMessageBuilder
{
    Subject = "Quarterly report",
    Body = "The report is attached.",
    SenderName = "Alice",
    SenderEmailAddress = "alice@example.com",
    SenderAddressType = "SMTP",
};
message.Recipients.Add(new MapiRecipientBuilder("Bob", "bob@example.com"));
message.Attachments.Add(MapiAttachmentBuilder.FromContent("report.csv", "Quarter,Total\nQ1,42\n"u8.ToArray(), "text/csv"));
MsgFile.Save(message, path);

var item = MsgFile.Load(path);
Assert.Equal("Quarterly report", item.Subject);
Assert.Equal("bob@example.com", item.Recipients.Single().EmailAddress);
Assert.Equal("report.csv", item.Attachments.Single().Name);

Convert a message

// An item of an Outlook data file, saved as an .eml file
using (var file = PstFile.Open(pstPath))
{
    var item = file.GetFolder("Inbox")!.EnumerateItems().First();
    EmailMessage.FromMapi(item).ToMime().WriteTo(emlPath);
}

// The .eml file, read back
var email = EmailMessage.FromMime(MimeMessage.Load(emlPath));
Assert.Equal("Welcome to Microsoft Office Outlook 2003", email.Subject);
Assert.HasCount(11, email.Attachments);
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 60 11/21/2026