สร้าง, บันทึก, และอ่านโน้ต Outlook ใน C++

Aspose.Email for C++ ช่วยให้คุณสร้างและจัดการ Outlook Notes อย่างอัตโนมัติ. The MapiNote คลาสนี้ให้คุณสมบัติหลักทั้งหมด เช่น หัวเรื่อง, ข้อความในเนื้อหา, สี, และขนาด - เพื่อสร้างและปรับแต่งโน้ต.

บทความนี้สาธิตวิธีสร้าง, บันทึกและอ่านโน้ต Outlook ที่เก็บในรูปแบบ MSG การจัดเก็บโน้ตในไฟล์ PST จะอยู่ใน การทำงานกับ MapiNote ใน PST.

ตัวอย่างในบทความนี้ใช้ส่วนหัวและเนมสเปซต่อไปนี้:

#include <Mapi/MapiMessage.h>
#include <Mapi/MapiNote.h>
#include <Mapi/NoteColor.h>
#include <Mapi/NoteSaveFormat.h>
#include <Mapi/MapiItemType.h>
#include <system/convert.h>

using namespace System;
using namespace Aspose::Email::Mapi;

สร้างและบันทึกโน้ต Outlook

เพื่อสร้างและบันทึกโน้ต Outlook ลงดิสก์ ให้ทำตามขั้นตอนต่อไปนี้:

  1. สร้างอินสแตนซ์ของ MapiNote อ็อบเจ็กต์.
  2. ตั้งคุณสมบัติโน้ต เช่น หัวเรื่อง, เนื้อหา, สี, ความสูง, และความกว้าง.
  3. บันทึกโน้ตด้วย MapiNote::Save และ NoteSaveFormat::Msg.

สีเป็นหนึ่งใน NoteColor values; ความกว้างและความสูงกำหนดขนาดของหน้าต่างที่ Outlook เปิดโน้ตเป็นพิกเซล

SharedPtr<MapiNote> note = MakeObject<MapiNote>();
note->set_Subject(u"Blue color note");
note->set_Body(u"This is a blue color note");
note->set_Color(NoteColor::Blue);
note->set_Height(500);
note->set_Width(500);
note->Save(u"MapiNote_out.msg", NoteSaveFormat::Msg);

อ่าน Outlook Note

โน้ตที่บันทึกเป็นไฟล์ MSG จะโหลดเป็น MapiMessage, และ ToMapiMessageItem เปลี่ยนเป็น MapiNote. การตรวจสอบ get_SupportedType แรกตรวจสอบว่าไฟล์จริงเป็นโน้ต - DynamicCast ขว้างข้อยกเว้นเมื่อไอเท็มเป็นประเภทอื่น.

SharedPtr<MapiMessage> message = MapiMessage::Load(u"MapiNote_out.msg");

if (message->get_SupportedType() == MapiItemType::Note)
{
    SharedPtr<MapiNote> note = DynamicCast<MapiNote>(message->ToMapiMessageItem());
    Console::WriteLine(u"Subject: " + note->get_Subject());
    Console::WriteLine(u"Body: " + note->get_Body());
    Console::WriteLine(u"Size: " + Convert::ToString(note->get_Width()) + u"x" + Convert::ToString(note->get_Height()));
    Console::WriteLine(String(u"Blue: ") + (note->get_Color() == NoteColor::Blue ? u"yes" : u"no"));
}