소개
C++에서 Outlook MSG 파일을 다루는 것은 역사적으로 Windows 전용 COM 자동화가 필요했습니다
또는 제한적인 라이선스를 가진 무거운 서드파티 라이브러리가 필요했습니다. Aspose.Email FOSS for C++
이를 바꿉니다: 순수 C++17 라이브러리로 외부 종속성이 없으며, COM도 없고,
플랫폼 특정 코드도 없습니다. Linux, macOS 및 Windows에서 동일하게 빌드됩니다.
이 라이브러리는 MIT 라이선스로 배포되며 GitHub를 통해 소스 형태로 제공됩니다. 당신은
저장소를 복제하고 CMake 하위 디렉터리로 추가하여 통합합니다 — 패키지
매니저 등록이 필요 없으며, 사전 빌드된 바이너리가 필요하지 않습니다.
이 게시물에서는 핵심 워크플로를 단계별로 살펴봅니다: 기존 MSG 파일을 읽고, 해당 파일의 속성을 검사하며, 프로그래밍 방식으로 새 메시지를 생성하고, MSG와 EML 형식 간을 왕복합니다.
핵심 기능
기존 MSG 파일 읽기
msg_reader을 사용하여 .msg 파일을 열고 msg_document을 사용하여 해당 구조화된 콘텐츠에 접근합니다. 두 클래스는 aspose::email::foss::msg 네임스페이스에 있습니다.
#include "aspose/email/foss/msg/msg_reader.hpp"
#include "aspose/email/foss/msg/msg_document.hpp"
#include <filesystem>
namespace aef = aspose::email::foss;
auto reader = aef::msg::msg_reader::from_file(std::filesystem::path("message.msg"));
auto document = aef::msg::msg_document::from_reader(reader);
msg_reader은 std::istream에서 읽기 위한 from_stream 오버로드도 제공하며, 이는 파일이 디스크에 존재하지 않는 서버 측 또는 파이프라인 상황에서 유용합니다.
프로그래밍 방식으로 메시지 생성
mapi_message::create은(는) 제목과 본문을 가진 새로운 인메모리 메시지를 생성합니다.
그런 다음 발신자 세부 정보를 설정하고, 수신자를 추가하며, 저장하기 전에 바이너리 또는 텍스트 페이로드를 첨부할 수 있습니다.
#include "aspose/email/foss/msg/mapi_message.hpp"
namespace aef = aspose::email::foss;
auto msg = aef::msg::mapi_message::create(
"Quarterly status update",
"Hello team,\n\nPlease find the rollout summary attached.\n\nRegards");
msg.set_sender_name("Build Agent");
msg.set_sender_email_address("build.agent@example.com");
msg.add_recipient("alice@example.com", "Alice Example");
msg.save(std::filesystem::path("output.msg"));
MSG를 EML로 변환
mapi_message은 save_to_eml 메서드를 통해 MSG를 EML로 직접 변환하는 것을 지원합니다.
EML 출력은 RFC 5322 (MIME)를 준수하므로 모든 표준 메일
클라이언트 또는 처리 파이프라인과 호환됩니다.
auto loaded = aef::msg::mapi_message::from_file(
std::filesystem::path("message.msg"), /*strict=*/false);
// Save as EML to a file
loaded.save_to_eml(std::filesystem::path("message.eml"));
// Or capture as bytes
std::vector<std::uint8_t> eml_bytes = loaded.save_to_eml();
EML에서 로드
역방향도 마찬가지로 간단합니다: load_from_eml은 EML 파일을 읽고 메모리에서 mapi_message을 생성한 다음, 이를 다시 MSG로 저장할 수 있습니다.
auto from_eml = aef::msg::mapi_message::load_from_eml(
std::filesystem::path("message.eml"));
from_eml.save(std::filesystem::path("restored.msg"));
저수준 CFB 액세스
고급 사용 사례 — 예를 들어 고수준 API에서 노출되지 않은 원시 MAPI 속성을 읽는 경우 — cfb_reader는 MSG 형식의 기반이 되는 복합 파일 바이너리 컨테이너에 직접 접근을 제공합니다.
#include "aspose/email/foss/cfb/cfb_reader.hpp"
namespace aef = aspose::email::foss;
auto cfb = aef::cfb::cfb_reader::from_file(std::filesystem::path("message.msg"));
auto storage_ids = cfb.storage_ids();
auto stream_ids = cfb.stream_ids();
빠른 시작
1단계 — 복제하고 하위 디렉터리로 추가
git clone https://github.com/aspose-email-foss/Aspose.Email-FOSS-for-Cpp.git
프로젝트 CMakeLists.txt에서:
cmake_minimum_required(VERSION 3.26)
project(my_project)
add_subdirectory(Aspose.Email-FOSS-for-Cpp)
add_executable(my_app main.cpp)
target_link_libraries(my_app PRIVATE AsposeEmailFoss::AsposeEmailFoss)
2단계 — 포함 및 사용
#include <iostream>
#include "aspose/email/foss/msg/mapi_message.hpp"
namespace aef = aspose::email::foss;
int main()
{
// Create a message
auto msg = aef::msg::mapi_message::create("Hello from C++", "Body text here");
msg.save(std::filesystem::path("hello.msg"));
// Round-trip to EML
auto loaded = aef::msg::mapi_message::from_file(
std::filesystem::path("hello.msg"), false);
loaded.save_to_eml(std::filesystem::path("hello.eml"));
std::cout << "Done\n";
}
3단계 — 빌드
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
지원되는 형식
| 형식 | 확장자 | 읽기 | 쓰기 |
|---|---|---|---|
| MSG (Outlook Message) | .msg | ✓ | ✓ |
| EML (RFC 5322 / MIME) | .eml | ✓ | ✓ |
| CFB (Compound File Binary) | .msg, .cfb | ✓ | ✓ |
오픈 소스 및 라이선스
Aspose.Email FOSS for C++는 MIT 라이선스로 배포됩니다. 전체 소스는
GitHub의 aspose-email-foss/Aspose.Email-FOSS-for-Cpp에서 확인할 수 있습니다.
상업적 사용은 로열티 없이 허용됩니다. 이 라이브러리는 런타임 종속성이 없습니다
C++17 컴파일러와 CMake 3.26 이상을 제외하고는.