Read the complete article on how to parse PST files and extract messages and contacts in Python: https://blog.aspose.com/email/parse-outlook-pst-files-in-python/
Last active
January 7, 2025 14:41
Parse Outlook PST Files in Python | Extract Messages and Contacts from PST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
I am having the same error as matchkid530
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
aspose.email' has no attribute 'PersonalStorage'