PST फ़ाइलों में Outlook संपर्कों का प्रबंधन

Add Outlook Contacts to PST Files

नया PST फ़ाइल बनाएं और सबफ़ोल्डर जोड़ें यह दर्शाता है कि कैसे PST फ़ाइल बनाएं और उसमें सबफ़ोल्डर शामिल करें। Aspose.Email के साथ आप बनाए या लोड की गई PST फ़ाइल के Contacts सबफ़ोल्डर में MapiContact जोड़ सकते हैं। नीचे PST फ़ाइल में MapiContact जोड़ने के चरण दिए गए हैं:

  1. एक बनाएं MapiContact ऑब्जेक्ट।
  2. विभिन्न कंस्ट्रक्टर्स और मेथड्स का उपयोग करके MapiContact की प्रॉपर्टीज़ जैसे नाम, लिंग, ईमेल एड्रेस, टेलीफ़ोन नंबर, भौतिक पते, और प्रोफेशनल जानकारी सेट करें।
  3. के उपयोग से PST बनाएं PersonalStorage.create() विधि।
  4. PST फ़ाइल की रूट पर एक पूर्व-परिभाषित फ़ोल्डर (Contacts) बनाएं, रूट फ़ोल्डर को एक्सेस करके और फिर add_mapi_message_item() विधि।

निम्नलिखित कोड स्निपेट दर्शाता है कि कैसे MAPI संपर्क बनाएं और फिर उसे नए बनाए गए PST फ़ाइल के Contacts फ़ोल्डर में जोड़ें:

Save Outlook Contacts as MSG Files

Outlook PST फ़ाइल से संपर्क जानकारी तक पहुंचने और संपर्क को डिस्क पर MSG फ़ॉर्मेट में सहेजने के लिए, Aspose.Email प्रदान करता है PersonalStorage और MapiContact क्लासेज़। नीचे दिया गया कोड स्निपेट दिखाता है कि कैसे PST फ़ाइल से सभी संपर्क जानकारी प्राप्त करें और उसे डिस्क पर MSG फ़ॉर्मेट में सहेजें:

  1. PST फ़ाइल लोड करें PersonalStorage क्लास।
  2. Contacts फ़ोल्डर ब्राउज़ करें।
  3. संदेश संग्रह प्राप्त करने के लिए Contacts फ़ोल्डर की सामग्री प्राप्त करें।
  4. संदेश संग्रह के माध्यम से लूप करें।
  5. कॉल करें PersonalStorage.extract_message() संपर्क जानकारी प्राप्त करने की विधि जिसमें MapiMessage क्लास।
  6. कॉल करें MapiMessage.save() संपर्क को डिस्क पर MSG फ़ॉर्मेट में सहेजने की विधि।

Export Outlook Contacts as VCF Files

Microsoft Outlook PST फ़ाइल से संपर्क जानकारी प्राप्त करने और संपर्क को डिस्क पर vCard (VCF) फ़ॉर्मेट में सहेजने के लिए, उपयोग करें PersonalStorage और MapiContact क्लासेज़। नीचे दिया गया कोड डिस्क से PST फ़ाइल लोड करता है और सभी संपर्कों को vCard (VCF) फ़ॉर्मेट में सहेजता है। VCF फ़ाइलें फिर किसी भी अन्य प्रोग्राम में इस्तेमाल की जा सकती हैं जो मानक vCard संपर्क फ़ाइल लोड कर सके। यदि आप Microsoft Outlook में कोई VCF फ़ाइल खोलते हैं, तो वह नीचे दिए स्क्रीनशॉट जैसा दिखेगा।

todo:image_alt_text

निम्नलिखित कोड स्निपेट दिखाता है कि कैसे Outlook PST से संपर्कों को vCard (VCF) फ़ॉर्मेट में एक्सपोर्ट करें:

  1. उपयोग करें PersonalStorage.from_file PST फ़ाइल खोलने के लिए।
  2. उपयोग करके Contacts फ़ोल्डर तक पहुँचें get_sub_folder.
  3. संपर्कों पर लूप करें:
    • उपयोग करें get_contents() फ़ोल्डर में सभी संदेश जानकारी प्राप्त करने के लिए।
    • के माध्यम से दोहराएँ message_info_collection एक लूप के साथ।
  4. उपयोग करके प्रत्येक संपर्क निकालें pst.extract_message(message_info) और इसे MAPI संदेश आइटम के रूप में सहेजें।
  5. प्रत्येक संपर्क का नाम और एंट्री आईडी प्रिंट करें।
  6. उपयोग करके संपर्क को VCF फ़ाइल के रूप में सहेजें contact.save.
from aspose.email.storage.pst import PersonalStorage
from aspose.email.mapi import ContactSaveFormat

# Load the Outlook PST file
pst = PersonalStorage.from_file("my.pst")

# Get the Contacts folder
folder_info = pst.root_folder.get_sub_folder("Contacts")

# Loop through all the contacts in this folder
message_info_collection = folder_info.get_contents()
for message_info in message_info_collection:
    # Get the contact information
    contact = pst.extract_message(message_info).to_mapi_message_item()

    # Display some contents on screen
    print("Name: " + contact.name_info.display_name + " - " + message_info.entry_id_string)

    # Save to disk in vCard VCF format
    contact.save("D:\\" + contact.name_info.display_name + ".vcf", ContactSaveFormat.V_CARD)

Managing Outlook Distribution Lists in PST Files

Aspose.Email for Python API के ज़रिए एक डिस्ट्रिब्यूशन लिस्ट बनाना संभव है - कई संपर्कों का संग्रह। डिस्ट्रिब्यूशन लिस्ट को Outlook MSG फ़ॉर्मेट में डिस्क पर सहेजा जा सकता है और इसे MS Outlook में खोलकर देखा/संशोधित किया जा सकता है।

वितरण सूचियाँ बनाएं और सहेजें

नीचे दिया गया कोड स्निपेट दर्शाता है कि कैसे PST फ़ाइल बनाएं और डिस्ट्रिब्यूशन लिस्ट जोड़ें। इसमें PST फ़ाइल के भीतर डिस्ट्रिब्यूशन लिस्ट में संपर्क बनाना और जोड़ना भी शामिल है।

  1. संपर्क विवरण परिभाषित करें - प्रत्येक संपर्क के लिए displayName और email सेट करें।
  2. उपयोग करके एक नई PST फ़ाइल बनाएं PersonalStorage.create() UNICODE फ़ॉर्मेट के साथ।
  3. उपयोग करके Contacts फ़ोल्डर बनाएं create_predefined_folder().
  4. इंस्टैंशिएट करें MapiContact डिस्प्ले नाम और ईमेल वाले ऑब्जेक्ट्स, फिर फ़ोल्डर में संपर्क जोड़ें, उपयोग करके add_mapi_message_item().
  5. इंस्टैंसिएट करके डिस्ट्रिब्यूशन लिस्ट सदस्य बनाएं MapiDistributionListMember प्रत्येक संपर्क के लिए और एंट्री_आईडी को बेस64 डिकोडिंग से सेट करते हुए।
  6. में सदस्य जोड़ें MapiDistributionListMemberCollection.
  7. इंस्टैंसिएट करके एक डिस्ट्रिब्यूशन लिस्ट बनाएं MapiDistributionList, उसका बॉडी और सब्जेक्ट सेट करते हुए।
  8. उपयोग करें add_mapi_message_item() डिस्ट्रिब्यूशन लिस्ट को संपर्क फ़ोल्डर में जोड़ने के लिए।
displayName1 = "Sebastian Wright"
email1 = "SebastianWright@dayrep.com"

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

personalStorage = PersonalStorage.create(dataDir + "CreateDistributionListInPST_out.pst", FileFormatVersion.UNICODE)

contactFolder = personalStorage.create_predefined_folder("Contacts", StandardIpmFolder.CONTACTS)

   # Create contacts
   strEntryId1 = contactFolder.add_mapi_message_item(MapiContact(displayName1, email1))
   strEntryId2 = contactFolder.add_mapi_message_item( MapiContact(displayName2, email2))

   member1 = MapiDistributionListMember(displayName1, email1)
   member1.entry_id_type = MapiDistributionListEntryIdType.CONTACT
   member1.entry_id = base64.b64decode( bytes(strEntryId1, "utf-8") )

   member2 = MapiDistributionListMember(displayName2, email2)
   member2.entry_id_type = MapiDistributionListEntryIdType.CONTACT
   member2.entry_id = base64.b64decode( bytes(strEntryId1, "utf-8") )

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

   distribution_list = MapiDistributionList("Contact list", members)
   distribution_list.body = "Distribution List Body"
   distribution_list.subject = "Sample Distribution List using Aspose.Email"     
                    
   # Add distribution list to PST 
   contactFolder.add_mapi_message_item(distribution_list);

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

निम्नलिखित कोड स्निपेट दिखाता है कि कैसे PST फ़ाइल से डिस्ट्रिब्यूशन लिस्ट पढ़ें:

from aspose.email.mapi import MapiMessage

# Load the MAPI message from file
message = MapiMessage.load("dl.msg")

# Convert the message to MAPI distribution list
dlist = message.to_mapi_message_item()

Update Distribution Lists in Outlook PST Files

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

import aspose.email as ae

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 = pst.extract_message(msg).to_mapi_message_item()
        # Create a new member to add
        member = ae.mapi.MapiDistributionListMember("Edward R. Manuel", "EdwardRManuel@example.com")
        dist_list.members.append(member)
        # Update DL in PST
        folder.update_message(msg.entry_id_string, dist_list)