डिस्ट्रिब्यूशन लिस्ट्स के साथ काम करना

Aspose.Email API का उपयोग करके एक डिस्ट्रीब्यूशन लिस्ट बनाना संभव है, जो कई संपर्कों का संग्रह होती है। एक डिस्ट्रीब्यूशन लिस्ट को Outlook MSG फ़ॉर्मेट में डिस्क पर सेव किया जा सकता है और इसे MS 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);
}

एकल मल्टी-कॉन्टैक्ट VCF फ़ाइल में Mapi डिस्ट्रिब्यूशन लिस्ट सहेजें

यह 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();