How to parse / read Outlook PST-Files with Python?
Asked Answered
L

1

8

Searching the Internet for accessing Outlook PST-Files with Python gives very little results (and most of the stuff shown is outdated). Does anyone know how to read a PST with or without a library? Unfortunately I am not good enough in programming to build a PST-reader without the help of a library.

My target is to get the following information about the content:

  • Number of Items per Folder
  • Type of Item (Mail, Meeting, Contact...)
  • Size of Items
  • Attachments including size
  • maybe other Meta-Data like date, recipients etc. (optional)

I already tried the following things:

  1. libpff / pypff : crashes and seems to read whole file in memory before doing something (no good solution as the PST-files are kept on a slow network storage).

  2. Libratom : same problem as it is based on libpff.

  3. Libpst : unclear how this is used / comes as a binary (no explanation how to install) / see answer on this post / does not seems to be maintained or updated.

  4. win32 (mounting PST in Outlook) : one tutorial showed how to mount the PST into a locally installed Outlook and getting the contents with MAPI-access, but this is also very, very slow and not a good solution as Outlook is needed.

  5. Asponse Email Python : promising at the start though documentation is not very good (no Python examples / different naming e.g. for the PersonalStorage object and many others / stops after 50 items per folder (maybe a limit of the non-free version, but unclear due to lack of explanation on the publishers website).

This is an example from the Asponse-website:

personalStorage = PersonalStorage.from_file(dataDir + "Outlook.pst")

folderInfoCollection = personalStorage.root_folder.get_sub_folders()

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))
    print("----------------------")

I did heavy googling to find the fitting import-statement to make this run.

Does anyone have a stable clear approach for reading Outlook PST files? Even a solution using Asponse would be great exceeding the 50 items limit.

Linkboy answered 9/11, 2021 at 21:25 Comment(5)
That is 11 years ago! Was there no progress on this topic due to that time?Linkboy
@Grismar most telling is the comment (from early 2017, 7 years after the OP) on the linked question: "Please un-close this so I can share my new solution"Studhorse
I'm sure people have good advice and wonderful opinions, but that's besides the point. If OP (here or there) had tried a solution and ran into problems, that would make for a valid SO question. For opinions, Quora is not bad. I do appreciate that OP on this question provided some info on the options they tried and it does seem there's no great solution on hand, but it changes little about the type of discussion that's likely to follow.Triphthong
There are descriptions how to read a PST-file directly, but that is far beyond my abilities...Linkboy
@Triphthong - I am not sure where you have seen MS recommending that: PST is a local email storage mechanism, It has absolutely nothing to do with an Exchange mailbox, which can indeed be accessed using EWS or Graph. Were you thinking of OST?Hengel
H
2

Redemption (I am its author) can be another choice - it is a wrapper around Extended MAPI, so you would still need to have Outlook installed (for its MAPI system), but unlike Outlook Object Model, it can be used from a service and does not require starting outlook.exe and/or adding PST files to the user's default profile. You can use either RDOSession.LogonPstStore (it creates and deletes a temporary profile configured to use the specified PST file) and/or RDOSession.Stores.AddPstStore to the add a PST file to an existing session (e.g. used by Outlook or created by LogonPstStore).

Hengel answered 11/11, 2021 at 18:12 Comment(1)
Thanks for that! I will give it a try...Linkboy

© 2022 - 2024 — McMap. All rights reserved.