Το Aspose.Email FOSS for .NET είναι μια βιβλιοθήκη C# αδειοδοτημένη με MIT, χωρίς εξαρτήσεις, για εργασία με αρχεία .msg του Microsoft Outlook, δοχεία Compound File Binary (CFB) και μηνύματα EML. Προσθέστε ένα μόνο πακέτο NuGet και αρχίστε αμέσως να διαβάζετε, να δημιουργείτε και να επεξεργάζεστε μηνύματα ηλεκτρονικού ταχυδρομείου χωρίς να εγκαταστήσετε το Microsoft Outlook ή οποιοδήποτε ιδιόκτητο runtime.
Η βιβλιοθήκη παρέχει δύο επίπεδα πρόσβασης. Σε χαμηλό επίπεδο, τα CfbReader και CfbWriter παρέχουν πλήρη έλεγχο των δυαδικών δοχείων CFB — περιηγηθείτε στις καταχωρήσεις καταλόγου, διαβάστε και γράψτε κόμβους αποθήκευσης και δεδομένα ροής, και ελέγξτε τη γυμνή διάταξη των τομέων. Τα MsgReader και MsgWriter διαχειρίζονται τη μορφή MSG πάνω από το CFB, εκθέτοντας ροές ιδιοτήτων MAPI, πίνακες παραληπτών και υποαποθηκεύσεις συνημμένων. Σε υψηλό επίπεδο, το MapiMessage σας επιτρέπει να δημιουργήσετε νέα μηνύματα από το μηδέν, να διαβάσετε το θέμα, το σώμα, τον αποστολέα και τους παραλήπτες, να διαχειριστείτε τα συνημμένα και να μετατρέψετε μεταξύ των μορφών MSG και EML μέσω μιας ενσωματωμένης υλοποίησης MIME.
Η βιβλιοθήκη στοχεύει στο .NET 8.0 ή νεότερο και δεν έχει εγγενείς εξαρτήσεις, καθιστώντας την κατάλληλη για Windows, Linux, macOS, κοντέινερ Docker και λειτουργίες serverless.
CfbReader.FromFile(), CfbReader.FromStream(), or new CfbReader(data).IterStorages(), IterStreams(), IterChildren(), and IterTree().ResolvePath(names) to locate a specific stream by name chain.CfbDocument and serialize to bytes or file via CfbWriter.ToBytes() or CfbWriter.WriteFile().CfbStorage and CfbStream nodes to any storage node before serialization..msg files — direct CFB access enables forensic inspection and repair.MsgReader.FromFile() or MsgReader.FromStream() and access the underlying MAPI property streams, recipient records, and attachment sub-storages.MsgDocument with MsgWriter.ToBytes() or MsgWriter.WriteFile().MsgStorage, MsgStream, and MsgReader.ParseTopLevelPropertyStream().MsgStorage.FindStream() and MsgStorage.FindStorage() to locate named sub-entries..msg files from archive directories and extract metadata or attachments..msg files programmatically and deliver them to Outlook-based mail systems.MapiMessage.Create(subject, body), set SenderName, SenderEmailAddress, and HtmlBody.To, Cc, and Bcc recipients via AddRecipient() with email address and display name.AddAttachment() or construct MapiAttachment objects directly with Filename, MimeType, ContentId, and Data.message.Save() or message.Save(stream) and reload with MapiMessage.FromFile() or MapiMessage.FromStream().message.Attachments, and save each attachment.Data to disk.message.Subject, message.Body, message.SenderEmailAddress, and message.Recipients without COM automation..eml file (RFC 5322 / MIME) into a full MapiMessage object via MapiMessage.LoadFromEml(stream).MapiMessage back to MIME format with message.SaveToEml() or message.SaveToEml(stream)..eml and .msg files to a single format..eml fixtures in tests and verify they survive MSG round-trip without data loss.Open an Outlook MSG file from a stream and print the subject — no Microsoft Outlook required.
using System.IO;
using Aspose.Email.Foss.Msg;
using var stream = File.OpenRead("sample.msg");
var message = MapiMessage.FromStream(stream);
Console.WriteLine(message.Subject);
Build a complete email with sender, recipient, and attachment, then write it to an MSG file.
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);
Load a standard .eml file and save it as an Outlook .msg file using the built-in MIME parser.
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);