PST 파일에서 Outlook 배포 목록 관리

배포 목록은 자동화된 소프트웨어에 의해 조작될 수 있는 연락처 그룹으로, 사용자가 동시에 여러 수신자에게 이메일을 보낼 수 있도록 합니다.

Aspose.Email for Python API를 사용하면 사용자가 배포 목록을 생성, 관리 및 조작할 수 있습니다. 여기에는 목록의 멤버 생성 및 저장, 배포 목록 읽기, 목록 속성 업데이트 및 기타 관련 작업이 포함됩니다.

PST 파일에서 배포 목록 생성 및 저장

기존 PST 연락처가 포함된 배포 목록 추가

다음 코드 스니펫은 이미 PST 파일에 저장된 연락처를 포함하는 배포 목록을 만드는 방법을 보여줍니다.

  1. 다음으로 새 PST 파일을 생성합니다: PersonalStorage.create() UNICODE 형식으로.
  2. 미리 정의된 "Contacts" 폴더를 생성하고, 두 개의 연락처 항목(Sebastian Wright 및 Wichert Kroos)을 해당 폴더에 추가합니다.
  3. 연락처를 배포 목록에 추가합니다:
    • 각 연락처는 배포 목록에 다음 형태로 추가됩니다: MapiDistributionListMember.
    • 각 멤버의 entry_id는 인코딩된 strEntryId를 사용하여 해당 PST 연락처와 연결됩니다.
  4. "Contact list"라는 이름의 배포 목록을 생성하고, 추가된 연락처를 멤버로 포함시킨 뒤 PST 파일에 추가합니다.
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)

일회성 멤버가 포함된 배포 목록 추가

연락처가 Outlook 주소록에 포함되지 않지만 배포 목록에 포함되어야 할 경우 일회성 멤버가 적합합니다. 다음 코드 예제는 PST 파일에 저장되지 않은 연락처인 일회성 멤버와 함께 배포 목록을 만드는 방법을 보여줍니다.

  1. 다음으로 새 PST 파일을 생성합니다: PersonalStorage.create() UNICODE 형식으로.
  2. PST에서 연락처를 연결하는 대신, 새 연락처 항목(John R. Patrick 및 Tilly Bates)을 직접 일회성 멤버로 정의합니다.
  3. 일회성 멤버를 배포 목록에 추가합니다.
  4. 배포 목록을 생성하고, 이름을 "Simple list"로 지정한 뒤 PST 파일의 "Contacts" 폴더에 추가합니다.
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

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 파일에서 배포 리스트 업데이트

예를 들어 새 멤버를 추가하기 위해 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 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)