article

How to Reads Outlook PST File & Displays Folder or Message Information in Android using Java

Email
Submitted on: 11/18/2015 9:33:08 AM
By: Sherazam  
Level: Intermediate
User Rating: Unrated
Compatibility: Java (JDK 1.3), Java (JDK 1.4), Java (JDK 1.5)
Views: 3784
 
     This technical tip shows how to get the messages information from the Outlook PST file and display it inside .NET Applications. Previously we have discussed how to load an Outlook PST file and browse through its folders to get folder names and the number of messages in each folder. This topic explains how to read all the folders and subfolders in a PST file and display the information about messages, including subject, sender, recipients, and so on. The Outlook PST file may contain nested folders. To access them, a recursive method is needed.

 
				This technical tip shows how to get the messages information from the Outlook PST file and display it inside .NET Applications. Previously we have discussed how to load an Outlook PST file and browse through its folders to get folder names and the number of messages in each folder. This topic explains how to read all the folders and subfolders in a PST file and display the information about messages, including subject, sender, recipients, and so on. The Outlook PST file may contain nested folders. To access them, a recursive method is needed. Below is the complete source code of a console application that reads an Outlook PST file and displays the folder and message contents recursively.
//Get the Messages Information from the Outlook PST File
public void RetrievePSTFolderContents()
{
String strBaseFolder = Environment.getExternalStorageDirectory().getPath() + "/";
String pstFileName = strBaseFolder + "Outlook.pst";
try
{
// Load the Outlook PST file
PersonalStorage pst = PersonalStorage.fromFile(pstFileName);
// Get the root folder
FolderInfo folderInfo = pst.getRootFolder();
// Call the recursive method to display the folder contents
DisplayFolderContents(folderInfo, pst);
}
catch (Exception ex)
{
tx.setText(ex.getMessage());
}
}
private static void DisplayFolderContents(FolderInfo folderInfo, PersonalStorage pst)
{// Display the folder name
tx.setText(tx.getText() + "\n Folder: " + folderInfo.getDisplayName());
// Display information about messages inside this folder
MessageInfoCollection messageInfoCollection = folderInfo.getContents();
for (int i = 0; i < messageInfoCollection.size(); i++)
{
MessageInfo messageInfo = (MessageInfo) messageInfoCollection.get(i);
tx.setText(tx.getText() + "\n Subject: " + messageInfo.getSubject());
tx.setText(tx.getText() + "\n Sender: " + messageInfo.getSenderRepresentativeName());
tx.setText(tx.getText() + "\n To: " + messageInfo.getDisplayTo());
tx.setText(tx.getText() + "\n CC: " + messageInfo.getDisplayCC());
tx.setText(tx.getText() + "\n EntryID: " + messageInfo.getEntryIdString());
}
// Call this method recursively for each subfolder
if (folderInfo.hasSubFolders() == true)
{
for (int i = 0; i < folderInfo.getSubFolders().size(); i++)
{
FolderInfo subfolderInfo = (FolderInfo) folderInfo.getSubFolders().get(i);
DisplayFolderContents(subfolderInfo, pst);
}
}
}
Overview: Aspose.Email for Android
Aspose.Email for Android API enables developers to design Android applications for managing & manipulating Outlook email file formats without using MS Outlook. It provides tools to create, read & convert Outlook MSG, PST, EML, EMLX, OST & MHT file formats. It manages recipients, subject, message body, attachments in MSG documents. It creates & save appointments in draft format, extract & save calendar items from a PST, add Mapi Items such as Messages, Contacts, Notes, Journals & Tasks to a PST.


Other 6 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.