Aspose.Email FOSS for C++ 是一个 MIT 许可证的开源 C++ 库,用于处理 Microsoft Outlook .msg 文件和复合文件二进制(CFB)容器。通过 CMake 包含头文件,即可立即开始读取、创建和处理电子邮件,而无需安装 Microsoft Outlook 或任何专有运行时。
该库提供两个层次的访问。低层次的 cfb_reader 和 cfb_writer 提供对 CFB 二进制容器的完整控制——遍历目录条目,读取和写入存储节点和流数据,并检查原始扇区布局。msg_reader 和 msg_writer 在 CFB 之上处理 MSG 格式,公开 MAPI 属性流、收件人表和附件子存储。高层次的 mapi_message 让您可以从头创建新消息,读取主题、正文、收件人和附件,并在 MSG 与 EML 格式之间转换。
该库可在任何具备 C++17 编译器的平台上构建,且没有外部依赖,适用于 Windows、Linux、macOS、Docker 容器以及嵌入式系统。
cfb_reader::from_file(), cfb_reader::from_stream(), or cfb_reader::from_bytes().storage_ids(), stream_ids(), and child_ids(), and navigate nested hierarchies with resolve_path().cfb_node::is_storage() and cfb_node::is_stream(), read timestamps via creation_time() and modified_time().cfb_document and serialize to bytes or file via cfb_writer::to_bytes() or cfb_writer::write_file()..msg files — direct CFB access enables forensic inspection and repair.msg_reader::from_file() or msg_reader::from_stream() and access the underlying MAPI property streams and attachment sub-storages.msg_document with msg_writer::to_bytes() or msg_writer::write_file().msg_document::major_version(), msg_document::minor_version(), and check strictness with msg_document::strict().msg_document::to_cfb_document()..msg files from archive directories and extract metadata or attachments.mapi_message::create(), then set subject, body, and HTML body via set_subject(), set_body(), and set_html_body().set_sender_name(), set_sender_email_address(), and set_sender_address_type() for the outgoing message.mapi_attachment::from_bytes() and mapi_attachment::from_stream(), and check for embedded messages via is_embedded_message().mapi_message::save() and reload with mapi_message::from_file() or mapi_message::from_stream()..eml file (RFC 5322 / MIME) into a full mapi_message object via mapi_message::load_from_eml().mapi_message back to MIME format with save_to_eml()..eml and .msg files to a single format.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';
}
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);
}