Quickstart
Quickstart: C++ में अपना पहला MSG फ़ाइल
यह गाइड एक पूर्ण, चलने योग्य उदाहरण बनाता है - एक ईमेल को संकलित करना, इसे एमएसजी फ़ाइल के रूप में बचाना, वापस लोड करना और इसे ईएमएल में परिवर्तित करने के लिए - केवल मानक सी ++ लाइब्रेरी और एस्पोजे.ईमेल फॉस् का उपयोग करके सी + + के साथ।.
Prerequisites
| Requirement | Detail |
|---|---|
| Compiler | C++17 या बाद (GCC 9+, Clang 10+, MSVC 2019+) |
| बनाए रखें सिस्टम | 3.26 या बाद में |
| Library | GitHub से क्लोन (देखें) Installation) |
| Dependencies | None |
चरण 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 उत्पादन में संरक्षित हैं।.
अगले कदम
- Installation — पूर्ण CMake परियोजना सेटअप और समर्थित प्लेटफार्मों
- Features - पूर्ण फ़ंक्शन संदर्भ सी ++ उदाहरणों के साथ
- डेवलपर गाइड - एमएसजी, ईएमएल, सीएफबी और मैपीआई संपत्ति पैदल चलना
- FAQ - लाइसेंस, प्रारूप समर्थन, ज्ञात सीमाएं