PST への MapiDistributionList の追加
Contents
[
Hide
]
新規 PST の作成、サブフォルダーとメッセージの追加 PST ファイルを作成しサブフォルダーを追加する方法を示しました。Aspose.Email を使用すると、 MapiDistributionList 作成または読み込んだ PST ファイルの Contacts サブフォルダーに。
EntryId を設定するために MapiDistributionListMember、base64String は次を使用して変換する必要があります Apache Commons Codec.
ファイルから MapiDistributionList をロード
以下のコードは、ファイルから MAPI 配布リストをロードします。
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
String dataDir = "data/";
MapiMessage msg = MapiMessage.load(dataDir + "DistList.msg");
MapiDistributionList dlist = (MapiDistributionList) msg.toMapiMessageItem();
System.out.println("Members: " + dlist.getMembers().size());
新しい MapiDistributionList を作成し、Contacts サブフォルダーに追加
以下は追加手順です MapiDistributionList PST に対して:
- 新しい PST を作成します。
- Contacts フォルダーを PST に追加します。
- サンプル連絡先を作成します。
- 作成した連絡先を基に配布リストを作成します。
- 配布リストを PST に追加します。
以下のコードスニペットは、次の作成方法を示します MapiDistributionList そして新規作成した PST ファイルの Contacts フォルダーに追加します。
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
String dataDir = "data/";
String displayName1 = "Sebastian Wright";
String email1 = "SebastianWright@dayrep.com";
String displayName2 = "Wichert Kroos";
String email2 = "WichertKroos@teleworm.us";
PersonalStorage pst = PersonalStorage.create(dataDir + "pstFileName1_out.pst", FileFormatVersion.Unicode);
// Add the contact folder to the PST
FolderInfo contactFolder = pst.createPredefinedFolder("Contacts", StandardIpmFolder.Contacts);
// Create the contacts; addMapiMessageItem returns the Base64-encoded entry ID
String strEntryId1 = contactFolder.addMapiMessageItem(new MapiContact(displayName1, email1));
String strEntryId2 = contactFolder.addMapiMessageItem(new MapiContact(displayName2, email2));
// Create a distribution list on the basis of the created contacts
MapiDistributionListMember member1 = new MapiDistributionListMember(displayName1, email1);
member1.setEntryIdType(MapiDistributionListEntryIdType.Contact);
member1.setEntryId(java.util.Base64.getDecoder().decode(strEntryId1));
MapiDistributionListMember member2 = new MapiDistributionListMember(displayName2, email2);
member2.setEntryIdType(MapiDistributionListEntryIdType.Contact);
member2.setEntryId(java.util.Base64.getDecoder().decode(strEntryId2));
MapiDistributionListMemberCollection members = new MapiDistributionListMemberCollection();
members.addItem(member1);
members.addItem(member2);
MapiDistributionList distributionList = new MapiDistributionList("Contact list", members);
distributionList.setBody("Distribution List Body!");
distributionList.setSubject("Distribution List Subject!");
// Add the distribution list to the PST
contactFolder.addMapiMessageItem(distributionList);
単発配布リストの作成
この配布リストには、別個の連絡先は必要ありません。
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
String dataDir = "data/";
PersonalStorage pst = PersonalStorage.create(dataDir + "pstFileName2_out.pst", FileFormatVersion.Unicode);
// Add the contact folder to the PST
FolderInfo contactFolder = pst.createPredefinedFolder("Contacts", StandardIpmFolder.Contacts);
MapiDistributionListMemberCollection oneOffMembers = new MapiDistributionListMemberCollection();
oneOffMembers.addItem(new MapiDistributionListMember("John R. Patrick", "JohnRPatrick@armyspy.com"));
oneOffMembers.addItem(new MapiDistributionListMember("Tilly Bates", "TillyBates@armyspy.com"));
MapiDistributionList oneOffMembersList = new MapiDistributionList("Simple list", oneOffMembers);
contactFolder.addMapiMessageItem(oneOffMembersList);