PST फ़ाइल में वितरण सूचियों के साथ काम करना

वितरण सूची संपर्कों का एक समूह है जिसे स्वचालित सॉफ़्टवेयर द्वारा नियंत्रित किया जा सकता है, जिससे उपयोगकर्ता एक साथ कई प्राप्तकर्ताओं को ईमेल भेज सकें।

Aspose.Email सॉफ्टवेयर उपयोगकर्ताओं को वितरण सूचियों को बनाने, प्रबंधित करने और नियंत्रित करने की अनुमति देता है। इसमें सूची से सदस्यों को बनाना और सहेजना, वितरण सूचियों को पढ़ना, सूची गुणों को अपडेट करना, और अन्य संबंधित संचालन शामिल हैं।

डिस्ट्रिब्यूशन लिस्ट बनाना और सहेजना

नीचे दिए गए कोड उदाहरण में दिखाए अनुसार एक वितरण सूची बनाएं और सहेजें:

import base64

import aspose.email as ae

displayName1 = "Sebastian Wright"
email1 = "SebastianWright@dayrep.com"

displayName2 = "Wichert Kroos"
email2 = "WichertKroos@teleworm.us"

pst = ae.storage.pst.PersonalStorage.create("target.pst", ae.storage.pst.FileFormatVersion.UNICODE)

contactFolder = pst.create_predefined_folder("Contacts", ae.storage.pst.StandardIpmFolder.CONTACTS)

strEntryId1 = contactFolder.add_mapi_message_item(ae.mapi.MapiContact(displayName1, email1))
strEntryId2 = contactFolder.add_mapi_message_item(ae.mapi.MapiContact(displayName2, email2))

member1 = ae.mapi.MapiDistributionListMember(displayName1, email1)
member1.entry_id_type = ae.mapi.MapiDistributionListEntryIdType.CONTACT
member1.entry_id = base64.b64decode(strEntryId1)

member2 = ae.mapi.MapiDistributionListMember(displayName2, email2)
member2.entry_id_type = ae.mapi.MapiDistributionListEntryIdType.CONTACT
member2.entry_id = base64.b64decode(strEntryId2)

members = ae.mapi.MapiDistributionListMemberCollection()
members.append(member1)
members.append(member2)

distributionList = ae.mapi.MapiDistributionList("Contact list", members)
distributionList.body = "Distribution List Body"
distributionList.subject = "Sample Distribution List using Aspose.Email"
# Add distribution list to PST
contactFolder.add_mapi_message_item(distributionList)
import base64

import aspose.email as ae

displayName1 = "Sebastian Wright"
email1 = "SebastianWright@dayrep.com"

displayName2 = "Wichert Kroos"
email2 = "WichertKroos@teleworm.us"

pst = ae.storage.pst.PersonalStorage.create("target.pst", ae.storage.pst.FileFormatVersion.UNICODE)

contact_folder = pst.create_predefined_folder("Contacts", ae.storage.pst.StandardIpmFolder.CONTACTS)

one_off_members = ae.mapi.MapiDistributionListMemberCollection()
one_off_members.append(ae.mapi.MapiDistributionListMember("John R. Patrick", "JohnRPatrick@armyspy.com"))
one_off_members.append(ae.mapi.MapiDistributionListMember("Tilly Bates", "TillyBates@armyspy.com"))

one_off_members_list = ae.mapi.MapiDistributionList("Simple list", one_off_members)
contact_folder.add_mapi_message_item(one_off_members_list)

PST से वितरण सूचियों को पढ़ना

PST से वितरण सूची पढ़ने के लिए, निम्नलिखित कोड उदाहरण का उपयोग करें:

import aspose.email as ae
import aspose.pycore as pycore

pst = ae.storage.pst.PersonalStorage.from_file("my.pst")

folder = pst.get_predefined_folder(ae.storage.pst.StandardIpmFolder.CONTACTS)

for msg in folder.enumerate_messages():
    # Check if the message has the "IPM.DistList" message class
    if msg.message_class == "IPM.DistList":
        dist_list = pycore.cast(ae.mapi.MapiDistributionList, pst.extract_message(msg).to_mapi_message_item())
        # Now, you can work with the distribution list
        # (e.g., access its members, display its properties, or make modifications)
        for member in dist_list.members:
            print(f"{member.display_name}")

PST में वितरण सूचियों को अपडेट करना

PST फ़ाइल में एक वितरण सूची को अपडेट करने के लिए, उदाहरण के लिए नई सदस्य जोड़ने हेतु, निम्नलिखित कोड नमूना उपयोग करें:

import aspose.email as ae
import aspose.pycore as pycore

pst = ae.storage.pst.PersonalStorage.from_file("my.pst")

folder = pst.get_predefined_folder(ae.storage.pst.StandardIpmFolder.CONTACTS)

# add a new member to each distribution list in pst
for msg in folder.enumerate_messages():
    # Check if the message has the "IPM.DistList" message class
    if msg.message_class == "IPM.DistList":
        dist_list = pycore.cast(ae.mapi.MapiDistributionList, pst.extract_message(msg).to_mapi_message_item())

        # The collection returned by the members property is detached from the
        # message, so rebuild it to make the change persistent
        members = ae.mapi.MapiDistributionListMemberCollection()
        for existing_member in dist_list.members:
            members.append(ae.mapi.MapiDistributionListMember(existing_member.display_name, existing_member.email_address))

        # Create new member to add
        members.append(ae.mapi.MapiDistributionListMember("Edward R. Manuel", "EdwardRManuel@example.com"))

        # update DL in PST
        folder.update_message(msg.entry_id_string, ae.mapi.MapiDistributionList(dist_list.display_name, members))