Working with Contacts in PST File

Reading Multiple Contacts in VCard Format

The code sample below demonstrates how to read a VCF file, check if it contains multiple contacts, and if so, load the contacts from the file into a list of VCardContact objects. The code uses the following methods:

try (InputStream stream = new FileInputStream("test.vcf")) {
    if (VCardContact.isMultiContacts(stream)) {
        List<VCardContact> contacts = VCardContact.loadAsMultiple(stream, Charset.forName("utf-8"));
    }
}

Adding Contact to PST

Create New PST, Add Sub-folders and Messages showed how to create a PST file and add a subfolder to it. With Aspose.Email you can add a MapiContact to the Contacts subfolder of a PST file that you have created or loaded. Below are the steps to add MapiContact to a PST:

  1. Create a MapiContact object.
  2. Set the MapiContact properties using different constructors and methods.
  3. Create a PST using the PersonalStorage.create() method.
  4. Create a pre-defined folder (Contacts) at the root of the PST file by accessing the root folder and then calling the addMapiMessageItem() method.

The code snippet below shows how to create a MapiContact and then add it to the Contacts folder of a newly created PST file.

Save contacts information from PST file in MSG Format

This article shows how to access contact information from a Microsoft Outlook PST file and save contacts to disk in MSG format. To do so, use the PersonalStorage and MapiContact classes to get and display the contact information.

To get a contact’s information:

  1. Load the PST file in the PersonalStorage class.
  2. Browse the Contacts folder.
  3. Get the contents of the Contacts folder to get the message collection.
  4. Loop through the message collection.
  5. Call PersonalStorage.extractMessage() and then toMapiMessageItem() method to get the contact information in the MapiContact class.
  6. Use MapiContact properties to access the contact information.
  7. Call the PersonalStorage.extractMessage() method to get the contact information in the MapiMessage class.
  8. Call the MapiMessage.save() method to save the contact to disk in MSG format.

Below is a sample code that retrieves all the contacts information from the PST file and saves it to disk in MSG format.

Save Contacts Information from Outlook PST to Disk in vCard format

This article shows how to access contact information from a Microsoft Outlook PST file and save the contact to disk in vCard (VCF) format. It uses the PersonalStorage and MapiContact classes to get the contact information.

Below are the steps to get the contacts information:

  1. Load the PST file in PersonalStorage class.
  2. Browse the Contacts folder.
  3. Get the contents of the Contacts folder to get the message collection.
  4. Loop through the message collection.
  5. Call the PersonalStorage.extractMessage() method to get the contact information in the MapiContact class.
  6. Use the properties of the MapiContact class to access the contact information.

The program below loads a PST file from disk and saves all the contacts in vCard (VCF) format. The VCF files can then be used in any other program that can load the standard vCard contact file. If you open any VCF file in Microsoft Outlook, it will look like the one in the below screenshot.

todo:image_alt_text
Figure: A vCard saved with Aspose.Email