PST Dosyalarında Outlook Dağıtım Listelerini Yönetme
Dağıtım listesi, otomatik yazılım tarafından manipüle edilebilen bir iletişim grubu olup, kullanıcının aynı anda birden fazla alıcıya e-posta göndermesini sağlar.
Aspose.Email for Python API, kullanıcıların dağıtım listeleri oluşturmasını, yönetmesini ve manipüle etmesini sağlar. Bu, listedeki üyeleri oluşturmayı ve kaydetmeyi, dağıtım listelerini okumayı, liste özelliklerini güncellemeyi ve ilgili diğer işlemleri içerir.
PST Dosyalarında Dağıtım Listelerini Oluşturun ve Kaydedin
Mevcut PST Kişileriyle Bir Dağıtım Listesi Ekle
Aşağıdaki kod parçacığı, PST dosyasında zaten depolanmış kişileri içeren bir dağıtım listesinin nasıl oluşturulacağını göstermektedir.
- Şunu kullanarak yeni bir PST dosyası oluşturun: PersonalStorage.create() UNICODE formatı ile.
- Önceden tanımlı bir "Contacts" klasörü oluşturun ve bu klasöre iki kişi girişi (Sebastian Wright ve Wichert Kroos) ekleyin.
- Kişileri dağıtım listesine ekleyin:
- Her kişi dağıtım listesine bir MapiDistributionListMember.
- Her üyenin entry_id‘si, kodlanmış strEntryId kullanılarak ilgili PST kişisine bağlanır.
- "Contact list" adında bir dağıtım listesi oluşturun; bu liste eklenen kişileri üye olarak içerir ve PST dosyasına ekleyin.
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 = strEntryId1.encode()
member2 = ae.mapi.MapiDistributionListMember(displayName2, email2)
member2.entry_id_type = ae.mapi.MapiDistributionListEntryIdType.CONTACT
member2.entry_id = strEntryId2.encode()
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)
Tek Seferlik Üyelerle Bir Dağıtım Listesi Ekle
Tek seferlik üyeler, kişilerin Outlook adres defterinin bir parçası olmadığı ancak yine de dağıtım listesine eklenmesi gerektiği durumlar için uygundur. Aşağıdaki kod örneği, PST dosyasında depolanmayan kişiler olan tek seferlik üyelerle bir dağıtım listesinin nasıl oluşturulacağını göstermektedir.
- Şunu kullanarak yeni bir PST dosyası oluşturun: PersonalStorage.create() UNICODE formatı ile.
- PST’den kişileri bağlamak yerine, yeni kişi girişlerini (John R. Patrick ve Tilly Bates) doğrudan tek seferlik üyeler olarak tanımlayın.
- Dağıtım listesine tek seferlik üyeleri ekleyin.
- "Simple list" adlı bir dağıtım listesi oluşturun ve bunu PST dosyasındaki "Contacts" klasörüne ekleyin.
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 Dosyalarından Dağıtım Listelerini Oku
Bir PST’den dağıtım listesini okumak için aşağıdaki kod örneğini kullanın:
import aspose.email as ae
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 = 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}")
Outlook PST Dosyalarında Dağıtım Listelerini Güncelle
Bir PST dosyasındaki dağıtım listesini, örneğin yeni bir üye eklemek için, güncellemek istiyorsanız aşağıdaki kod örneğini kullanın:
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 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)