1. ผลิตภัณฑ์
  2.   Aspose.Email
  3.   Aspose.Email FOSS สำหรับ C++ for C++

Aspose.Email FOSS สำหรับ C++

อ่าน, สร้าง, และประมวลผลไฟล์ Outlook MSG และคอนเทนเนอร์ CFB จาก C++ — ฟรีและโอเพ่นซอร์ส, ไม่ต้องพึ่งพา Microsoft Outlook.

ไลบรารี C++ แบบโอเพนซอร์สสำหรับไฟล์ MSG และ CFB

Aspose.Email FOSS for C++ เป็นไลบรารี C++ แบบเปิดต้นฉบับที่ใช้ใบอนุญาต MIT สำหรับทำงานกับไฟล์ .msg ของ Microsoft Outlook และคอนเทนเนอร์ Compound File Binary (CFB) รวมถึงการรวมส่วนหัวผ่าน CMake และเริ่มอ่าน สร้าง และประมวลผลข้อความอีเมลได้ทันทีโดยไม่ต้องติดตั้ง Microsoft Outlook หรือรันไทม์ที่เป็นกรรมสิทธิ์ใด ๆ

ไลบรารีนี้ให้การเข้าถึงสองระดับ ระดับต่ำ cfb_reader และ cfb_writer ให้การควบคุมเต็มรูปแบบเหนือคอนเทนเนอร์ไบนารี CFB — เดินทางผ่านรายการไดเรกทอรี อ่านและเขียนโหนดสตอเรจและข้อมูลสตรีม และตรวจสอบการจัดเรียงเซกเตอร์ดิบ msg_reader และ msg_writer จัดการรูปแบบ MSG บน CFB เปิดเผยสตรีมคุณสมบัติ MAPI ตารางผู้รับ และซับสตอเรจของไฟล์แนบ ระดับสูง mapi_message ให้คุณสร้างข้อความใหม่ตั้งแต่ต้น อ่านหัวเรื่อง เนื้อหา ผู้รับ และไฟล์แนบ และแปลงระหว่างรูปแบบ MSG และ EML

ไลบรารีนี้สามารถสร้างบนแพลตฟอร์มใด ๆ ที่มีคอมไพเลอร์ C++17 และไม่มีการพึ่งพาไลบรารีภายนอก ทำให้เหมาะสำหรับ Windows, Linux, macOS, คอนเทนเนอร์ Docker และระบบฝังตัว.

CFB Container Read and Write

  • Open CFB files: Load existing CFB containers from a file path, stream, or byte array via cfb_reader::from_file(), cfb_reader::from_stream(), or cfb_reader::from_bytes().
  • Traverse the directory tree: Enumerate storages and streams using storage_ids(), stream_ids(), and child_ids(), and navigate nested hierarchies with resolve_path().
  • Inspect nodes: Check node type with cfb_node::is_storage() and cfb_node::is_stream(), read timestamps via creation_time() and modified_time().
  • Write CFB containers: Build CFB documents programmatically with cfb_document and serialize to bytes or file via cfb_writer::to_bytes() or cfb_writer::write_file().

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.

MSG File Read and Write

  • Read MSG files: Open Outlook MSG files with msg_reader::from_file() or msg_reader::from_stream() and access the underlying MAPI property streams and attachment sub-storages.
  • Write MSG files: Produce MSG files from a msg_document with msg_writer::to_bytes() or msg_writer::write_file().
  • MSG document inspection: Access version metadata via msg_document::major_version(), msg_document::minor_version(), and check strictness with msg_document::strict().
  • Convert to CFB: Extract the underlying CFB document from an MSG file via msg_document::to_cfb_document().

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.

High-Level MAPI Message API

  • Create messages: Build a complete email with mapi_message::create(), then set subject, body, and HTML body via set_subject(), set_body(), and set_html_body().
  • Set sender details: Configure set_sender_name(), set_sender_email_address(), and set_sender_address_type() for the outgoing message.
  • Manage attachments: Load attachments from bytes or streams with mapi_attachment::from_bytes() and mapi_attachment::from_stream(), and check for embedded messages via is_embedded_message().
  • Save and reload: Serialize with mapi_message::save() and reload with mapi_message::from_file() or mapi_message::from_stream().

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 attachments, and save each to disk.

EML and MIME Conversion

  • Load EML into mapi_message: Parse a standard .eml file (RFC 5322 / MIME) into a full mapi_message object via mapi_message::load_from_eml().
  • Save mapi_message as EML: Serialize a mapi_message back to MIME format with save_to_eml().
  • Round-trip fidelity: Subject, body, sender, recipients, and attachments are preserved through EML to MSG to EML round-trips.

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.

Read Subject from an MSG File

Open an Outlook MSG file from a stream and print the subject — no Microsoft Outlook required.

#include <fstream>
#include <iostream>

#include "aspose/email/foss/msg/mapi_message.hpp"

int main()
{
    std::ifstream input("sample.msg", std::ios::binary);
    auto message = aspose::email::foss::msg::mapi_message::from_stream(input);
    std::cout << message.subject() << '\n';
}

Create and Save an MSG Message

Build a complete email with sender, recipient, and attachment, then write it to both MSG and EML formats.

#include <fstream>

#include "aspose/email/foss/msg/mapi_message.hpp"

int main()
{
    auto message = aspose::email::foss::msg::mapi_message::create("Hello", "Body");
    message.set_sender_name("Alice");
    message.set_sender_email_address("alice@example.com");
    message.add_recipient("bob@example.com", "Bob");
    message.add_attachment("note.txt", std::vector<std::uint8_t>{'a', 'b', 'c'}, "text/plain");

    std::ofstream msg_output("hello.msg", std::ios::binary);
    message.save(msg_output);

    std::ofstream eml_output("hello.eml", std::ios::binary);
    message.save_to_eml(eml_output);
}
 ภาษาไทย