Introduction
Aspose.Email FOSS for .NET is a free, open-source C# library that lets you work with Outlook MSG files, Compound File Binary (CFB) containers, and EML messages directly in your .NET application — no Microsoft Outlook, no COM interop, and no native libraries required. Distribute it as a single NuGet package and it runs identically on Windows, Linux, macOS, Docker containers, and serverless functions.
The library solves a recurring problem in enterprise and integration work: Outlook .msg files
are produced by millions of business users, but parsing them without Outlook has historically
required COM automation or expensive commercial libraries. Aspose.Email FOSS for .NET provides
full read/write support for MSG, the underlying CFB binary container, and the EML/MIME format —
all under the MIT license with no usage restrictions.
Whether you are building an email archival pipeline, a migration tool, an attachment extractor,
or an automated MSG generator, this library gives you direct, low-level access to every byte of
the email format alongside a high-level MapiMessage API that lets you get started in minutes.
Key Features
Read Outlook MSG Files
Open any .msg file from a path or stream with MsgReader.FromFile() or MsgReader.FromStream().
Access the complete MAPI property stream, recipient records, and attachment sub-storages at the
raw byte level via MsgStorage and MsgStream.
using System.IO;
using Aspose.Email.Foss.Msg;
using var stream = File.OpenRead("sample.msg");
var message = MapiMessage.FromStream(stream);
Console.WriteLine(message.Subject);
Create MSG Files from Scratch
Build a complete email programmatically using MapiMessage.Create(). Set the subject, plain-text
body, HTML body, sender name, sender email address, delivery time, and internet message ID, then
add recipients with AddRecipient() and attachments with AddAttachment(). Serialize with
message.Save().
using System.IO;
using Aspose.Email.Foss.Msg;
var message = MapiMessage.Create("Hello", "Body");
message.SenderName = "Alice";
message.SenderEmailAddress = "alice@example.com";
message.AddRecipient("bob@example.com", "Bob");
using var attachmentStream = new MemoryStream("abc"u8.ToArray());
message.AddAttachment("note.txt", attachmentStream, "text/plain");
using var output = File.Create("hello.msg");
message.Save(output);
Convert EML to MSG (and Back)
Load a standard RFC 5322 .eml file into a MapiMessage with MapiMessage.LoadFromEml(),
then save it as an Outlook .msg file — or reverse the process with MapiMessage.SaveToEml().
The built-in MIME parser preserves subject, body, HTML body, sender, recipients, and attachments
through full EML ↔ MSG round-trips.
using System.IO;
using Aspose.Email.Foss.Msg;
using var input = File.OpenRead("message.eml");
var message = MapiMessage.LoadFromEml(input);
using var msgOutput = File.Create("message.msg");
message.Save(msgOutput);
using var emlOutput = File.Create("roundtrip.eml");
message.SaveToEml(emlOutput);
Low-Level CFB Container Access
Outlook MSG files are built on the Compound File Binary (CFB) format — a hierarchical binary
container similar to a filesystem. CfbReader exposes the full directory tree: iterate storages
and streams with IterStorages(), IterStreams(), and IterChildren(), navigate to specific
entries by path with ResolvePath(), and read raw stream bytes with GetStreamData().
CfbWriter lets you construct and serialize a CFB document from scratch. Create a CfbDocument,
attach CfbStorage and CfbStream nodes, and call CfbWriter.ToBytes() or
CfbWriter.WriteFile() to serialize.
MAPI Property and Attachment Access
The MapiPropertyCollection class provides typed MAPI property access for any MSG or storage
object: use Get(), Set(), Add(), and Remove() with standard CommonMessagePropertyId
or PropertyTypeCode enum values. Access attachment metadata and binary data via
MapiAttachment properties: Filename, MimeType, ContentId, and Data.
Quick Start
Install the package:
dotnet add package Aspose.Email.Foss
Read a subject from an MSG file:
using System.IO;
using Aspose.Email.Foss.Msg;
using var stream = File.OpenRead("sample.msg");
var message = MapiMessage.FromStream(stream);
Console.WriteLine(message.Subject);
Console.WriteLine(message.SenderEmailAddress);
foreach (var recipient in message.Recipients)
Console.WriteLine($"To: {recipient.EmailAddress}");
foreach (var attachment in message.Attachments)
Console.WriteLine($"Attachment: {attachment.Filename} ({attachment.MimeType})");
Supported Formats
| Format | Extension | Read | Write |
|---|---|---|---|
| Compound File Binary | .cfb | ✓ | ✓ |
| Outlook Message | .msg | ✓ | ✓ |
| MIME / EML | .eml | ✓ | ✓ |
Open Source & Licensing
Aspose.Email FOSS for .NET is released under the MIT license. You may use it freely in personal, commercial, and open-source projects with no usage restrictions. The source code is available at github.com/aspose-email-foss/Aspose.Email-FOSS-for-.Net.