Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active April 22, 2024 15:48
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/1dbac77d1d7eb9df7f20f2091c19db50 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/1dbac77d1d7eb9df7f20f2091c19db50 to your computer and use it in GitHub Desktop.
Create PST Files in Python
# Create a PST file
with PersonalStorage.create("sample.pst", FileFormatVersion.UNICODE) as pst:
# Access the folder to add items
inbox_folder = pst.root_folder.get_sub_folder("Inbox")
# Create a new message
message = MapiMessage("from@example.com", "to@example.com", "Subject", "Body")
# Add the message to the Inbox folder
inbox_folder.add_message(message)
# Create a PST file
with PersonalStorage.create("sample.pst", FileFormatVersion.UNICODE) as pst:
# Create a standard folder (Contacts)
contacts_folder = pst.create_predefined_folder("My Contacts", StandardIpmFolder.CONTACTS)
# Load a contact from vcf file
contact = MapiContact.from_v_card("Contact.vcf")
# Add the contact to the folder
contacts_folder.add_mapi_message_item(contact)
# Create a PST file
with PersonalStorage.create("sample.pst", FileFormatVersion.UNICODE) as pst:
# Create a custom folder
some_folder = pst.root_folder.add_sub_folder("SomeFolder")
# Create a subfolder to the custom folder
sub_folder = some_folder.add_sub_folder("SubFolder")
inbox_folder = pst.create_predefined_folder("Inbox", PersonalStorage.StandardIpmFolder.INBOX)
pst_path = "output.pst"
pst = PersonalStorage.create(pst_path, PersonalStorage.UNICODE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment