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);