How to Get Started with Aspose.Email FOSS for .NET
This guide walks you through installing the library, reading your first MSG file, creating a message from scratch, and converting between EML and MSG formats.
Step 1 — Install the Package
dotnet add package Aspose.Email.FossNo additional configuration is needed. The package has no native dependencies.
Step 2 — Read an MSG File
Create a console app and add the following code:
using System.IO;
using Aspose.Email.Foss.Msg;
using var stream = File.OpenRead("sample.msg");
var message = MapiMessage.FromStream(stream);
Console.WriteLine($"Subject: {message.Subject}");
Console.WriteLine($"From: {message.SenderEmailAddress}");
Console.WriteLine($"Body: {message.Body}");
foreach (var recipient in message.Recipients)
Console.WriteLine($"To: {recipient.EmailAddress}");
foreach (var attachment in message.Attachments)
Console.WriteLine($"Attachment: {attachment.Filename} ({attachment.MimeType})");MapiMessage.FromStream() parses the MSG file’s CFB container and exposes all MAPI
properties through strongly-typed C# properties. No Microsoft Outlook is required.
Step 3 — Create a New MSG File
using System.IO;
using Aspose.Email.Foss.Msg;
var message = MapiMessage.Create("Meeting Notes", "Please find the notes attached.");
message.SenderName = "Alice";
message.SenderEmailAddress = "alice@example.com";
message.AddRecipient("bob@example.com", "Bob");
// Add a file attachment
message.AddAttachment("notes.txt", System.Text.Encoding.UTF8.GetBytes("Meeting notes here"), "text/plain");
// Save to file
message.Save("meeting_notes.msg");
Console.WriteLine("Created meeting_notes.msg");MapiMessage.Create() produces an in-memory message. Save() serializes it to MSG format —
you can pass a file path, a Stream, or call Save() with no arguments to get a byte[].
Step 4 — Convert EML to MSG
using System.IO;
using Aspose.Email.Foss.Msg;
// Load from EML
using var input = File.OpenRead("message.eml");
var message = MapiMessage.LoadFromEml(input);
Console.WriteLine($"Subject: {message.Subject}");
// Save as MSG
message.Save("converted.msg");
Console.WriteLine("Saved converted.msg");
// Or save back to EML (round-trip)
message.SaveToEml("roundtrip.eml");The built-in MIME parser preserves subject, body, HTML body, sender, recipients, and all attachments through full EML ↔ MSG round-trips.
Next Steps
- Features and Functionalities — complete feature reference with C# examples
- FAQ — answers to common questions
- Installation Guide — NuGet setup and .NET version requirements