QuickStart

Quickstart: הקובץ הראשון שלך MSG ב- C++

מדריך זה יוצר דוגמה מלאה, מתקדמת – מחברת דואר אלקטרוני, שמירה אותו כקובץ MSG, העלאתו בחזרה והפוך אותו ל- EML – באמצעות הספרייה הסטנדרטית C++ בלבד ו- Aspose.Email FOSS עבור C ++ .


דרישות

דרישותפרטים
קומפלרC++17 או מאוחר יותר (GCC 9+, Clang 10+, MSVC 2019+)
בניית מערכת3.26 או מאוחר יותר
ספרייהמונח על ידי GitHub (ראה ההתקנה)
תלויותאף אחד

שלב 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

הפוך את קובץ MSG לתבנית RFC 5322 / MIME עם 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;
}

נושא, גוף, שרתים, קבלנים והחבילה נשמרים כולם בתוצאה EML.


שלבים הבאים

  • ההתקנה - הגדרת פרויקט CMake מלאה ופלטפורמות תומכות
  • תכונות – רשימה מלאה של תכונות עם דוגמאות C++
  • מדריך מפתחים - MSG, EML, CFB ו- MAPI נכסים מסלולי הליכה
  • FAQ - רישיון, תמיכה בפורמט, הגבלות ידועות

ראה גם

 עברית