Aspose.email to list pst items

Thank you for aspose!
I am trying to list emails from a local pst file, and the code works, but two issues:

  1. the To: field shows a name, not the actual email address which is in the email headers.
    In the headers it shows guthrie@miu.edu, but the code prints my full name, which is nowhere in the headers. ??
  2. In outlook, many folders say: “more items on the server”, and none of them are listed. Is this because I am listing from a pst file which is a static snapshot of the “live” ost file,or actual exchange data?
  3. How do I iinclde the From: field?
    I dodn’t find any similar examples.
    Thanks.
   pst = PersonalStorage.from_file(dataDir + dataFile)

  folderInfo = pst.root_folder
 # Display information about messages inside this folder
    messageInfoCollection = folderInfo.get_contents()

    for messageInfo in messageInfoCollection:
            # print ("F.om: "    + messageInfo.from_address)  <--Fails
            print ("Subject: " + messageInfo.subject)
            print ("To: "      + messageInfo.display_to)

Hello @guthrie,

Thank you for contacting Aspose.Email support forum!

The MessageInfo class doesn’t display all message properties. This is due to the peculiarities of PST structures.
To display recipient addresses, you can use the extract_recipients method. To display the sender, you can use messageInfo.sender_representative_name:

import aspose.email as ae

pst = ae.storage.pst.PersonalStorage.from_file("/media/sd/Data/Aspose/souce storages/barry.pst")

folderInfo = pst.root_folder.get_sub_folder("Inbox")
# Display information about messages inside this folder
messageInfoCollection = folderInfo.get_contents()

for messageInfo in messageInfoCollection:
    print ("From: " + messageInfo.sender_representative_name)
    print ("Subject: " + messageInfo.subject)
    # get message recipients
    recipients = pst.extract_recipients(messageInfo)
    addresses = [r.display_name + ' <'+ r.email_address + '>' for r in recipients]
    print ("To: " + ', '.join(addresses))

But keep in mind that sender_representative_name doesn’t always return the sender’s address. For a guaranteed way to obtain the sender’s address, use the extract_property(entry_id, tag) method of PersonalStorage, where entry_id is the message ID, and tag is the property tag, such as MapiPropertyTag.SENDER_EMAIL_ADDRESS_W.

The message “more items on the server” in Outlook usually indicates that you are viewing a cached or partial view of your mailbox. This is because you are working with a .pst file, which is a static snapshot of your data at a certain point in time.

Perfect, very helpful, thanks.
Is there a parallel way to read from the ost file, or even directly from the exchange server - to thus get all entries?

@guthrie,

You can read OST as well as PST. The difference is that OST files are used with Microsoft Exchange Server or Microsoft 365 accounts.
PST and OST are stored locally on a user’s computer and can be accessed even when the user is not connected to the email server.

You can retrieve messages from the server using the IMAP client. Please refer to the code examples in the documentation.

Thank you.