Quickstart

Quickstart: İlk MSG dosyanız C++‘da

Bu kılavuz, bir e-posta oluşturmak, MSG dosyası olarak kaydetmek, geri yüklemek ve EML’ye dönüştürmek için tam ve çalışabilir bir örnek oluşturur - yalnızca standart C++ kütüphanesi ve Aspose.Email FOSS kullanarak C ++ için.


Prerequisites

RequirementDetail
CompilerC++17 veya sonraki (GCC 9+, Clang 10+, MSVC 2019+)
Sistem Yapımı3.26 veya daha sonraki
LibraryGitHub’dan Clone (GitHub’a bakın) Installation)
DependenciesNone

Adım 1: CMakeLists.txt’inizi ayarlayın

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)

Adım 2: Bir MSG dosyası oluşturun ve kaydedin

Konu, vücut, gönderen, bir alıcı ve bir ek ile yeni bir MSG dosyası oluşturun:

#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;
}

Yapı ve koşu:

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

Dosya hello.msg iş dizininde oluşturulur. Outlook’ta açılır doğrulamak için, 3. Adımını programlı olarak tekrar okuyun.


Adım 3: MSG Dosyası Geri Okuyun

Sadece oluşturduğun dosyayı yükleyin ve özelliklerini yazdırın:

#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;
}

Beklenen çıktı:

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)

Adım 4: EML’ye dönüştürün

MSG dosyasını RFC 5322 / MIME formatına dönüştürün. save_to_eml():

#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;
}

Konu, vücut, gönderen, alıcılar ve ek tüm EML çıkışında korunur.


Sonraki adımlar

  • Installation — Tam CMake projesi kurulumu ve desteklenen platformlar
  • Features - Tam özellik referansı C++ örnekleri ile
  • Geliştirici Rehberi MSG, EML, CFB ve MAPI mülkiyet yürüyüşleri
  • FAQ - lisans, format desteği, bilinen kısıtlamalar

See Also

 Türkçe