Добавление MapiDistributionList в PST

Создание нового PST, добавление подпапок и сообщений показало, как создать файл PST и добавить в него подпапку. С помощью Aspose.Email вы можете добавить MapiDistributionList в подпапку Контакты файла PST, который вы создали или загрузили.

Загрузка MapiDistributionList из файла

Код ниже загружает MAPI-список рассылки из файла.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
MapiMessage msg = MapiMessage.fromFile(dataDir + "DistList.msg");
MapiDistributionList dlist = (MapiDistributionList) msg.toMapiMessageItem();

Создание нового MapiDistributionList и добавление его в подпапку Контакты

Ниже приведены шаги для добавления MapiDistributionList в PST:

  1. Создайте новый PST.
  2. Добавьте папку Контакты в PST.
  3. Создайте примеры контактов.
  4. Создайте список рассылки на основе созданных контактов.
  5. Добавьте список рассылки в PST.

Код ниже показывает, как создать MapiDistributionList и затем добавить его в папку Контакты вновь созданного файла PST.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
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
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 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);
byte[] decodedBytes = Base64.decodeBase64(strEntryId1);
member1.setEntryId(decodedBytes);
MapiDistributionListMember member2 = new MapiDistributionListMember(displayName2, email2);
member2.setEntryIdType(MapiDistributionListEntryIdType.Contact);
decodedBytes = Base64.decodeBase64(strEntryId2);
member2.setEntryId(decodedBytes);
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 distribution list to PST
contactFolder.addMapiMessageItem(distributionList);

Создание разового списка рассылки

Для этого списка рассылки отдельные контакты не требуются.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
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);