Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active April 18, 2022 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/aaf32c39df10712c3958c113b95f11bb to your computer and use it in GitHub Desktop.
Save aspose-com-gists/aaf32c39df10712c3958c113b95f11bb to your computer and use it in GitHub Desktop.
Create Outlook Distribution Lists in Python
from aspose.email.storage.pst import *
from aspose.email.storage import PersonalStorage
from aspose.email.mapi import MapiContact
from aspose.email.mapi import MapiDistributionListMember, MapiDistributionList
from aspose.email.mapi import MapiDistributionListEntryIdType, MapiDistributionListMemberCollection
from aspose.email import StandardIpmFolder, FileFormatVersion
import base64
# Create members
displayName1 = "Sebastian Wright"
email1 = "SebastianWright@dayrep.com"
displayName2 = "Wichert Kroos"
email2 = "WichertKroos@teleworm.us"
# Create a PST file to store distribution list
personalStorage = PersonalStorage.create( "DistributionList.pst", FileFormatVersion.UNICODE)
# Create folder
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))
# Create distribution list members
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") )
# Add members to the collection
members = MapiDistributionListMemberCollection()
members.append(member1)
members.append(member2)
# Add collection to the list
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment