Quickstart

빠른 시작: C++에서 첫 번째 MSG 파일 만들기

이 가이드는 표준 C++ 라이브러리와 Aspose.Email FOSS for C++만을 사용하여 — 이메일을 작성하고, MSG 파일로 저장한 뒤 다시 로드하며, EML로 변환하는 — 완전하고 실행 가능한 예제를 생성합니다.


필수 조건

요구 사항세부 사항
CompilerC++17 이상 (GCC 9+, Clang 10+, MSVC 2019+)
빌드 시스템CMake 3.26 이상
Library복제 위치: GitHub (참조 Installation)
DependenciesNone

1단계: CMakeLists.txt 설정

cmake_minimum_required(VERSION 3.26)
project(email_quickstart)

add_subdirectory(Aspose.Email-FOSS-for-Cpp)

add_executable(quickstart main.cpp)
target_link_libraries(quickstart PRIVATE AsposeEmailFoss::AsposeEmailFoss)
set_target_properties(quickstart PROPERTIES CXX_STANDARD 17)

2단계: MSG 파일 만들기 및 저장

제목, 본문, 발신자, 수신자 및 첨부 파일이 포함된 새 MSG 파일을 만듭니다:

#include <fstream>
#include <vector>
#include "aspose/email/foss/msg/mapi_message.hpp"

int main()
{
    // Compose the message
    auto message = aspose::email::foss::msg::mapi_message::create(
        "Hello from Aspose.Email FOSS",
        "This message was created programmatically — no Outlook required.");

    message.set_sender_name("Alice");
    message.set_sender_email_address("alice@example.com");
    message.add_recipient("bob@example.com", "Bob");
    message.add_attachment(
        "readme.txt",
        std::vector<std::uint8_t>{'H', 'e', 'l', 'l', 'o', '\n'},
        "text/plain");

    // Save to MSG file
    std::ofstream out("hello.msg", std::ios::binary);
    message.save(out);

    return 0;
}

빌드 및 실행:

cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
./build/quickstart

파일 hello.msg이(가) 작업 디렉터리에 생성되었습니다. Outlook에서 열어 확인하거나, 프로그래밍 방식으로 다시 읽으려면 3단계로 진행하세요.


3단계: MSG 파일 다시 읽기

방금 만든 파일을 로드하고 속성을 출력합니다:

#include <fstream>
#include <iostream>
#include "aspose/email/foss/msg/mapi_message.hpp"

int main()
{
    std::ifstream input("hello.msg", std::ios::binary);
    const auto message = aspose::email::foss::msg::mapi_message::from_stream(input);

    std::cout << "Subject:     " << message.subject() << '\n';
    std::cout << "From:        " << message.sender_name()
              << " <" << message.sender_email_address() << ">\n";
    std::cout << "Body:        " << message.body() << '\n';
    std::cout << "Recipients:  " << message.recipients().size() << '\n';
    std::cout << "Attachments: " << message.attachments().size() << '\n';

    for (const auto& a : message.attachments())
        std::cout << "  - " << a.filename << " (" << a.data.size() << " bytes)\n";

    return 0;
}

예상 출력:

Subject:     Hello from Aspose.Email FOSS
From:        Alice <alice@example.com>
Body:        This message was created programmatically — no Outlook required.
Recipients:  1
Attachments: 1
  - readme.txt (6 bytes)

4단계: EML로 변환

save_to_eml()를 사용하여 MSG 파일을 RFC 5322 / MIME 형식으로 변환합니다:

#include <filesystem>
#include <iostream>
#include "aspose/email/foss/msg/mapi_message.hpp"

int main()
{
    const auto message = aspose::email::foss::msg::mapi_message::from_file(
        std::filesystem::path("hello.msg"));

    message.save_to_eml(std::filesystem::path("hello.eml"));
    std::cout << "Saved hello.eml\n";

    return 0;
}

제목, 본문, 발신자, 수신자 및 첨부 파일이 모두 EML 출력에 보존됩니다.


다음 단계

  • Installation — 전체 CMake 프로젝트 설정 및 지원되는 플랫폼
  • Features — C++ 예제가 포함된 전체 기능 레퍼런스
  • 개발자 가이드 — MSG, EML, CFB 및 MAPI 속성 가이드
  • FAQ — 라이선스, 형식 지원, 알려진 제한 사항

참조

 한국어