处理通讯组列表
Contents
[
Hide
]
使用 Aspose.Email API 可以创建一个分发列表,它是多个联系人集合。分发列表可以以 Outlook MSG 格式保存到磁盘,并且可以通过在 Microsoft Outlook 中打开进行查看/操作。
创建并保存通讯组列表
以下代码片段展示了如何创建并保存通讯组列表。
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "outlook/";
String displayName1 = "Sebastian Wright";
String email1 = "SebastianWright@dayrep.com";
String displayName2 = "Wichert Kroos";
String email2 = "WichertKroos@teleworm.us";
String strEntryId1;
String strEntryId2;
// Create distribution list from contacts
try (PersonalStorage personalStorage = PersonalStorage.create(dataDir + "CreateDistributionListInPST_out.pst", FileFormatVersion.Unicode)) {
// Add the contact folder to pst
FolderInfo contactFolder = personalStorage.createPredefinedFolder("Contacts", StandardIpmFolder.Contacts);
// Create contacts
strEntryId1 = contactFolder.addMapiMessageItem(new MapiContact(displayName1, email1));
strEntryId2 = contactFolder.addMapiMessageItem(new MapiContact(displayName2, email2));
// Create distribution list on the base of the created contacts
MapiDistributionListMember member1 = new MapiDistributionListMember(displayName1, email1);
member1.setEntryIdType(MapiDistributionListEntryIdType.Contact);
member1.setEntryId(Base64.getDecoder().decode(strEntryId1));
MapiDistributionListMember member2 = new MapiDistributionListMember(displayName2, email2);
member2.setEntryIdType(MapiDistributionListEntryIdType.Contact);
member2.setEntryId(Base64.getDecoder().decode(strEntryId2));
MapiDistributionListMemberCollection members = new MapiDistributionListMemberCollection();
members.add(member1);
members.add(member2);
MapiDistributionList distributionList = new MapiDistributionList("Contact list", members);
distributionList.setBody("Distribution List Body");
distributionList.setSubject("Sample Distribution List using Aspose.Email");
// Add distribution list to PST
contactFolder.addMapiMessageItem(distributionList);
}
// Create one-off distribution list members (for which no separate contacts were created)
try (PersonalStorage personalStorage = PersonalStorage.create(dataDir + "CreateDistributionListInPST_OneOffmembers_out.pst", FileFormatVersion.Unicode)) {
// Add the contact folder to pst
FolderInfo contactFolder = personalStorage.createPredefinedFolder("Contacts", StandardIpmFolder.Contacts);
MapiDistributionListMemberCollection oneOffmembers = new MapiDistributionListMemberCollection();
oneOffmembers.add(new MapiDistributionListMember("John R. Patrick", "JohnRPatrick@armyspy.com"));
oneOffmembers.add(new MapiDistributionListMember("Tilly Bates", "TillyBates@armyspy.com"));
MapiDistributionList oneOffMembersList = new MapiDistributionList("Simple list", oneOffmembers);
contactFolder.addMapiMessageItem(oneOffMembersList);
}
将 Mapi 通讯组列表保存为单个多联系人 VCF 文件
该 void save(String fileName, MapiDistributionListSaveOptions options) 此方法允许使用提供的保存选项将 Mapi 通讯组列表保存到指定的文件名。您可以提供文件名和该类的实例 MapiDistributionListSaveOptions 类作为参数。该 MapiDistributionListSaveOptions 此类包含保存 Mapi 通讯组列表的选项。在这种情况下,您可以将保存格式指定为 VCard(ContactSaveFormat.VCard),以将通讯组列表保存为多联系人 VCF 文件。
以下代码片段演示了如何将通讯组列表保存为多联系人 VCF 文件:
MapiDistributionList dlist = (MapiDistributionList)msg.toMapiMessageItem();
MapiDistributionListSaveOptions options = new MapiDistributionListSaveOptions(ContactSaveFormat.VCard);
dlist.save("distribution_list.vcf", options);
从 PST 读取通讯组列表
以下代码片段展示了如何从 PST 文件读取通讯组列表。
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String fileName = "outlook/message.msg";
MapiMessage message = MapiMessage.fromFile(fileName);
MapiDistributionList dlist = (MapiDistributionList)message.toMapiMessageItem();