소개

이 게시물은 Aspose.Email FOSS을 사용하여 C++에서 Outlook MSG 파일을 읽고, 생성하고, 변환하는 핵심 워크플로우를 단계별로 안내합니다 — 외부 종속성이 없고 COM이 없는 순수 C++17, MIT 라이선스 라이브러리입니다. 기존 MSG 파일을 읽고, 속성을 검사하며, 프로그래밍 방식으로 새 메시지를 생성하고, MSG와 EML 형식 간 라운드 트립을 수행하는 방법을 배울 수 있습니다.

이 라이브러리는 Linux, macOS, Windows에서 동일하게 빌드됩니다. GitHub을 통해 소스 형태로 배포되며, 리포지토리를 클론하고 CMake 서브디렉터리로 추가함으로써 통합됩니다 — 패키지 매니저 등록이 필요하지 않습니다.


핵심 기능

기존 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 형식의 기반이 되는 Compound File Binary 컨테이너에 직접 접근할 수 있게 합니다.

#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 프로젝트에서 add_subdirectory을(를) 사용해 참조합니다:

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단계 — 포함하고 사용하기

mapi_message 헤더를 포함하고 MSG 파일을 생성하고 EML로 변환하는 간단한 프로그램을 작성합니다:

#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 명령을 실행하여 구성하고 컴파일합니다:

cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build

지원되는 형식

형식확장자읽기쓰기Notes
MSG.msg✓✓Outlook 메시지 형식
EML.eml✓✓RFC 5322 / MIME 이메일 형식

CFB 메모. MSG 파일은 내부적으로 Compound File Binary 형식으로 저장됩니다. 라이브러리는 로드할 때 CBF 구조를 투명하게 읽어들입니다. .msg 파일; 별도의 CFB 포맷 클래스가 필요하지 않습니다.


오픈 소스 및 라이선스

Aspose.Email FOSS for C++는 MIT 라이선스로 배포됩니다. 전체 소스는 GitHub에서 aspose-email-foss/Aspose.Email-FOSS-for-Cpp에 있습니다. 상업적 사용은 로열티 없이 허용됩니다. 이 라이브러리는 C++17 컴파일러와 CMake 3.26 이상 외에 런타임 의존성이 없습니다.


시작하기

관련 리소스