Quickstart
Quickstart: اولین فایل MSG شما در C++
این راهنمای یک مثال کامل و قابل اجرا را ایجاد می کند – با ساختن ایمیل، ذخیره آن به عنوان یک فایل MSG، بارگذاری آن و تبدیل آن را به EML – فقط با استفاده از کتابخانه استاندارد C++ و Aspose.Email FOSS برای C ++.
Prerequisites
| Requirement | Detail |
|---|---|
| Compiler | C++17 یا بالاتر (GCC 9+، Clang 10+ و MSVC 2019+) |
| ساختن سیستم | 3.26 یا بعد از آن |
| Library | در GitHub (نگاه کنید به Installation) |
| Dependencies | None |
مرحله اول: تنظیم 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)مرحله دوم: ایجاد و ذخیره فایل 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)مرحله چهارم: تبدیل به 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 حفظ شده است.
قدم های بعدی
- Installation – تنظیم کامل پروژه CMake و پلتفرم های پشتیبانی شده
- Features – ارجاع کامل با نمونه های C++
- راهنمای توسعه دهنده - MSG، EML، CFB و MAPI املاک راه رفتن
- FAQ – مجوز، پشتیبانی از فرمت، محدودیت های شناخته شده