1. محصولات
  2.   Aspose.Email
  3.   Aspose.Email FOSS برای .NET for .NET

Aspose.Email FOSS برای .NET

فایل‌های Outlook MSG، کانتینرهای CFB و پیام‌های EML را از .NET بخوانید، ایجاد کنید و پردازش کنید — رایگان و منبع باز، بدون وابستگی به Microsoft Outlook.

کتابخانه منبع باز .NET برای فایل‌های MSG، CFB و EML

Aspose.Email FOSS برای .NET یک کتابخانه C# بدون وابستگی، تحت مجوز MIT است که برای کار با فایل‌های .msg مایکروسافت آوتلوک، کانتینرهای Compound File Binary (CFB) و پیام‌های EML استفاده می‌شود. یک بسته NuGet اضافه کنید و بلافاصله شروع به خواندن، ایجاد و پردازش پیام‌های ایمیل کنید بدون نصب مایکروسافت آوتلوک یا هر زمان‌اجرای مالکیتی.

این کتابخانه دو سطح دسترسی ارائه می‌دهد. در سطح پایین، CfbReader و CfbWriter کنترل کامل بر روی کانتینرهای باینری CFB را فراهم می‌کنند — مرور ورودی‌های دایرکتوری، خواندن و نوشتن گره‌های ذخیره‌سازی و داده‌های جریان، و بررسی چیدمان خام سکتورها. MsgReader و MsgWriter فرمت MSG را بر پایه CFB مدیریت می‌کنند و جریان‌های ویژگی MAPI، جداول دریافت‌کنندگان و زیرذخیره‌سازی‌های پیوست را در دسترس می‌گذارند. در سطح بالا، MapiMessage به شما امکان می‌دهد پیام‌های جدید را از ابتدا ایجاد کنید، موضوع، بدنه، فرستنده و دریافت‌کنندگان را بخوانید، پیوست‌ها را مدیریت کنید و بین فرمت‌های MSG و EML از طریق یک پیاده‌سازی داخلی MIME تبدیل کنید.

این کتابخانه برای .NET 8.0 یا نسخه‌های بعدی هدف‌گذاری شده است و هیچ وابستگی بومی ندارد، به‌طوری که برای ویندوز، لینوکس، macOS، کانتینرهای Docker و توابع سرورلس مناسب است.

CFB Container Read and Write

  • Open CFB files: Load existing CFB containers from a file path, stream, or byte array via CfbReader.FromFile(), CfbReader.FromStream(), or new CfbReader(data).
  • Traverse the directory tree: Iterate storages, streams, and children using IterStorages(), IterStreams(), IterChildren(), and IterTree().
  • Resolve paths: Navigate nested storage hierarchies with ResolvePath(names) to locate a specific stream by name chain.
  • Write CFB containers: Build CFB documents programmatically with CfbDocument and serialize to bytes or file via CfbWriter.ToBytes() or CfbWriter.WriteFile().
  • Add storages and streams: Attach CfbStorage and CfbStream nodes to any storage node before serialization.

Where CFB Access Is Used

  • MSG file inspection: CFB is the container format for Outlook .msg files — direct CFB access enables forensic inspection and repair.
  • Custom binary formats: Any legacy application using CFB for data storage can be read or written without a COM dependency.
  • Data recovery: Traverse the full directory tree and extract raw stream bytes from damaged or non-standard CFB files.
  • Binary round-trip testing: Serialize a document to bytes and reload it to verify lossless serialization in automated tests.

MSG File Read and Write

  • Read MSG files: Open Outlook MSG files with MsgReader.FromFile() or MsgReader.FromStream() and access the underlying MAPI property streams, recipient records, and attachment sub-storages.
  • Write MSG files: Produce MSG files from a MsgDocument with MsgWriter.ToBytes() or MsgWriter.WriteFile().
  • Low-level MAPI access: Read top-level property streams, named properties, and attachment data via MsgStorage, MsgStream, and MsgReader.ParseTopLevelPropertyStream().
  • MSG storage navigation: Use MsgStorage.FindStream() and MsgStorage.FindStorage() to locate named sub-entries.

Where MSG Processing Is Used

  • Email archival pipelines: Bulk-read .msg files from archive directories and extract metadata or attachments.
  • Migration tools: Convert MSG collections to standard formats for import into non-Outlook systems.
  • Legal discovery: Parse raw MAPI property streams to extract all message fields including non-standard properties.
  • Automated report delivery: Construct .msg files programmatically and deliver them to Outlook-based mail systems.

High-Level Message API

  • Create messages: Build a complete email with MapiMessage.Create(subject, body), set SenderName, SenderEmailAddress, and HtmlBody.
  • Add recipients: Attach To, Cc, and Bcc recipients via AddRecipient() with email address and display name.
  • Manage attachments: Add file and stream attachments with AddAttachment() or construct MapiAttachment objects directly with Filename, MimeType, ContentId, and Data.
  • Save and reload: Serialize with message.Save() or message.Save(stream) and reload with MapiMessage.FromFile() or MapiMessage.FromStream().

Where the High-Level API Is Used

  • Automated email generation: Generate thousands of personalized MSG files from data records in batch jobs.
  • Test fixture creation: Build known-good MSG files with predictable content for integration test suites.
  • Attachment extraction: Load an MSG file, iterate message.Attachments, and save each attachment.Data to disk.
  • Property inspection: Access message.Subject, message.Body, message.SenderEmailAddress, and message.Recipients without COM automation.

EML and MIME Conversion

  • Load EML into MapiMessage: Parse a standard .eml file (RFC 5322 / MIME) into a full MapiMessage object via MapiMessage.LoadFromEml(stream).
  • Save MapiMessage as EML: Serialize a MapiMessage back to MIME format with message.SaveToEml() or message.SaveToEml(stream).
  • Round-trip fidelity: Subject, body, HTML body, sender, recipients, and attachments are all preserved through EML → MSG → EML round-trips.
  • No external MIME parser: EML parsing is implemented natively within the library — no System.Net.Mail dependency required.

Where EML Conversion Is Used

  • Format bridging: Receive emails as EML from mail servers and convert to MSG for Outlook-compatible storage.
  • Standards compliance: Convert proprietary MSG files to standard MIME for delivery to any mail transport.
  • Archival normalization: Normalize a mixed archive of .eml and .msg files to a single format.
  • Testing workflows: Generate .eml fixtures in tests and verify they survive MSG round-trip without data loss.

Read Subject from an MSG File

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);

Create and Save an MSG Message

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);

Convert EML to MSG

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);
 فارسی