Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. aspose-com-gists revised this gist May 9, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    Read the complete article on how to create and read MS Outlook distribution lists in Java:
    Read the complete article on how to create and read MS Outlook distribution lists in Java: https://blog.aspose.com/2022/05/06/create-ms-outlook-distribution-lists-in-java/
  2. aspose-com-gists created this gist May 2, 2022.
    42 changes: 42 additions & 0 deletions create-outlook-distribution-list.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    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 + "list.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 a collection to keep members
    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));

    // Add members to collection
    MapiDistributionListMemberCollection members = new MapiDistributionListMemberCollection();
    members.add(member1);
    members.add(member2);

    // Create list
    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);
    }
    11 changes: 11 additions & 0 deletions read-outlook-distribution-list.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    // Load PST file
    MapiMessage message = MapiMessage.load("list.pst");

    // Fetch distribution list
    MapiDistributionList dlist = (MapiDistributionList)message.toMapiMessageItem();

    // Get members collection
    MapiDistributionListMemberCollection members = dlist.getMembers();

    // Read each MapiDistributionListMember from collection
    MapiDistributionListMember member1 = members.get(0);
    1 change: 1 addition & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    Read the complete article on how to create and read MS Outlook distribution lists in Java: