Agregar MapiDistributionList a PST
Contents
[
Hide
]
Crear nuevo PST, agregar subcarpetas y mensajes mostró cómo crear un archivo PST y agregarle una subcarpeta. Con Aspose.Email puedes agregar una MapiDistributionList a la subcarpeta de Contactos de un archivo PST que has creado o cargado.
Para establecer el EntryId para un MapiDistributionListMember, el base64String debe ser convertido usando Apache Commons Codec.
Cargar MapiDistributionList desde un archivo
El código a continuación carga una lista de distribución MAPI desde un archivo.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
Crear una nueva MapiDistributionList y agregarla a la subcarpeta de Contactos
A continuación se presentan los pasos para agregar una MapiDistributionList a un PST:
- Crear un nuevo PST.
- Agregar la carpeta de Contactos al PST.
- Crear contactos de ejemplo.
- Crear una lista de distribución sobre la base de los contactos creados.
- Agregar la lista de distribución al PST.
El fragmento de código a continuación muestra cómo crear una MapiDistributionList y luego agregarla a la carpeta de Contactos de un archivo PST recién creado.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
Crear una lista de distribución única
Para esta lista de distribución, no se requieren contactos separados.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |