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