Outlook 配布リストの操作
配布リスト は複数の受信者を 1 つの名前の下にまとめ、メッセージを一括で宛先指定できるようにします。Outlook はこのようなリストを連絡先の中に保持し、Aspose.Email for C++ はそれらを MapiDistributionList クラスです。この章は単独リスト、つまり自分自身の MSG または VCF ファイルとして保存されたリストを扱います。PST ファイル内に保存されたリストは PST ファイルでの配布リスト管理.
リストの各エントリは MapiDistributionListMember、に保存されます MapiDistributionListMemberCollection。名前とアドレスから作成されたメンバーは 一時的 メンバーです: 連絡先ストアの連絡先を指すのではなく、独自の詳細を保持します。これは単独ファイルが必要とするものです。
以下のサンプルはこれらのヘッダーと名前空間を使用しています:
#include <Mapi/MapiMessage.h>
#include <Mapi/MapiItemType.h>
#include <Mapi/MapiDistributionList.h>
#include <Mapi/MapiDistributionListMember.h>
#include <Mapi/MapiDistributionListMemberCollection.h>
#include <Mapi/MapiDistributionListSaveOptions.h>
#include <Mapi/ContactSaveFormat.h>
using namespace System;
using namespace Aspose::Email;
using namespace Aspose::Email::Mapi;
Create a Distribution List and Save It
この MapiDistributionList コンストラクタはリスト名とメンバーを受け取ります。 保存 選択された形式でリストを書き出します MapiDistributionListSaveOptions: ContactSaveFormat Msg Outlook アイテムを生成し、 VCard 他のアドレス帳がインポートできる VCF ファイルです。
// members that exist only inside this list
SharedPtr<MapiDistributionListMemberCollection> oneOffMembers = MakeObject<MapiDistributionListMemberCollection>();
oneOffMembers->Add(MakeObject<MapiDistributionListMember>(u"John R. Patrick", u"JohnRPatrick@armyspy.com"));
oneOffMembers->Add(MakeObject<MapiDistributionListMember>(u"Tilly Bates", u"TillyBates@armyspy.com"));
SharedPtr<MapiDistributionList> list = MakeObject<MapiDistributionList>(u"Simple list", oneOffMembers);
list->set_Body(u"Distribution List Body");
list->set_Subject(u"Sample Distribution List");
// the same list in both formats
list->Save(u"dlist.msg", MakeObject<MapiDistributionListSaveOptions>(ContactSaveFormat::Msg));
list->Save(u"dlist.vcf", MakeObject<MapiDistributionListSaveOptions>(ContactSaveFormat::VCard));
Read a Distribution List from an MSG File
MSG ファイルは次で開かれます MapiMessage::Load それが何を含んでいても。 SupportedType レポート MapiItemType::DistList 配布リスト用で、そして ToMapiMessageItem キャストされたアイテムを返します MapiDistributionList; それの Members そのコレクションリストは誰が所属しているかを示します。
SharedPtr<MapiMessage> msg = MapiMessage::Load(u"dlist.msg");
if (msg->get_SupportedType() == MapiItemType::DistList)
{
SharedPtr<MapiDistributionList> loaded = DynamicCast<MapiDistributionList>(msg->ToMapiMessageItem());
Console::WriteLine(u"List: " + loaded->get_DisplayName());
for (SharedPtr<MapiDistributionListMember> member : loaded->get_Members())
{
Console::WriteLine(u" " + member->get_DisplayName() + u" <" + member->get_EmailAddress() + u">");
}
}
複数の連絡先を保持する VCF ファイルは配布リストに変換できます - 詳細は 配布リストとマルチ連絡先 VCF ファイル.
Change the Members of a Saved List
保存されたリストを変更するには、メンバーを読み取り、それらから新しいメンバーコレクションを構築し、新しい MapiDistributionList 元の名前、件名、本文で作成し、古いファイルに上書き保存します。サンプルはメンバーを 1 つ削除し、別のメンバーを追加してファイルを再度読み込み、結果を表示します。
// a standalone list to start from
{
SharedPtr<MapiDistributionListMemberCollection> members = MakeObject<MapiDistributionListMemberCollection>();
members->Add(MakeObject<MapiDistributionListMember>(u"John R. Patrick", u"JohnRPatrick@armyspy.com"));
members->Add(MakeObject<MapiDistributionListMember>(u"Tilly Bates", u"TillyBates@armyspy.com"));
SharedPtr<MapiDistributionList> list = MakeObject<MapiDistributionList>(u"Simple list", members);
list->set_Subject(u"Simple list");
list->Save(u"team.msg", MakeObject<MapiDistributionListSaveOptions>(ContactSaveFormat::Msg));
}
SharedPtr<MapiDistributionList> stored = DynamicCast<MapiDistributionList>(MapiMessage::Load(u"team.msg")->ToMapiMessageItem());
// the new member list: everyone except John, plus Edward
SharedPtr<MapiDistributionListMemberCollection> members = MakeObject<MapiDistributionListMemberCollection>();
for (SharedPtr<MapiDistributionListMember> member : stored->get_Members())
{
if (member->get_EmailAddress() != u"JohnRPatrick@armyspy.com")
{
members->Add(MakeObject<MapiDistributionListMember>(member->get_DisplayName(), member->get_EmailAddress()));
}
}
members->Add(MakeObject<MapiDistributionListMember>(u"Edward R. Manuel", u"EdwardRManuel@armyspy.com"));
SharedPtr<MapiDistributionList> updated = MakeObject<MapiDistributionList>(stored->get_DisplayName(), members);
updated->set_Subject(stored->get_Subject());
updated->set_Body(stored->get_Body());
updated->Save(u"team.msg", MakeObject<MapiDistributionListSaveOptions>(ContactSaveFormat::Msg));
// read the file again
SharedPtr<MapiDistributionList> reloaded = DynamicCast<MapiDistributionList>(MapiMessage::Load(u"team.msg")->ToMapiMessageItem());
for (SharedPtr<MapiDistributionListMember> member : reloaded->get_Members())
{
Console::WriteLine(u" " + member->get_DisplayName() + u" <" + member->get_EmailAddress() + u">");
}
関連項目
- PST ファイルでの配布リスト管理 - PST に保存されたリストを作成、読み取り、更新し、メンバーを連絡先にリンクさせます。
- Outlook 連絡先の作成、保存、ロード - リストが参照できる連絡先アイテム。