在 C++ 中创建、保存和读取 Outlook 便签

Aspose.Email for C++ 允许您以编程方式创建和管理 Outlook 笔记。 The MapiNote 类提供所有基本属性——例如主题、正文文本、颜色和大小——用于创建和定制笔记。

本文演示如何创建、保存和读取以 MSG 格式存储的 Outlook 便笺。将便笺存储在 PST 文件中的内容见 在 PST 中使用 MapiNote.

本文中的示例使用了以下头文件和名称空间:

#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 值;宽度和高度设置 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 笔记

保存为 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"));
}