Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active November 5, 2023 09:19
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/1d9204a42d1674c51aab2a3db41be12f to your computer and use it in GitHub Desktop.
Save aspose-com-gists/1d9204a42d1674c51aab2a3db41be12f to your computer and use it in GitHub Desktop.
Parse Outlook PST Files in Python | Extract Messages and Contacts from PST
from aspose.email.storage.pst import PersonalStorage, StandardIpmFolder
from aspose.email.mapi import ContactSaveFormat
# Load PST file
pst = PersonalStorage.from_file("SampleContacts_out.pst")
# Select contacts folder
folderInfo = pst.get_predefined_folder(StandardIpmFolder.CONTACTS)
# Get contacts
contactCollection = folderInfo.get_contents()
# Loop through contacts collection
for messageInfo in contactCollection:
# Get the contact information
mapi = pst.extract_message(messageInfo)
contact = mapi.to_mapi_message_item()
# Display some contents on screen
print("Name: " + contact.name_info.display_name)
# Save to disc in MSG Format
if contact.name_info.display_name is not None:
# Save contact
contact.save("Contacts\\" + contact.name_info.display_name + "_out.msg")
contact.save("Contacts\\" + contact.name_info.display_name + "_out.vcf", ContactSaveFormat.VCARD)
from aspose.email.storage.pst import PersonalStorage
# Load PST file
sourcePst = PersonalStorage.from_file("Outlook.pst")
# Select desired folder
sourceFolder = sourcePst.root_folder.get_sub_folder("Inbox")
# Get content in the folder
messageInfoCollection = sourceFolder.get_contents()
# Loop through messages in folder
for messageInfo in messageInfoCollection:
print ("Subject: " + messageInfo.subject)
print("To: " + messageInfo.display_to)
from aspose.email.storage.pst import PersonalStorage
# Load PST file
personalStorage = PersonalStorage.from_file("Outlook.pst")
# Get folders' collection
folderInfoCollection = personalStorage.root_folder.get_sub_folders()
# Extract folders' information
for folderInfo in folderInfoCollection:
print("Folder: " + folderInfo.display_name)
print("Total Items: " + str(folderInfo.content_count))
print("Total Unread Items: " + str(folderInfo.content_unread_count))
@matchkid530
Copy link

aspose.email' has no attribute 'PersonalStorage'

@raymar
Copy link

raymar commented Nov 28, 2022

I am having the same error as matchkid530

@aspose-com-gists
Copy link
Author

aspose.email' has no attribute 'PersonalStorage'

we have updated code, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment