Create, Save and Read Outlook Contacts

Aspose.Email - Create, Save and Read Outlook Contacts

The following steps can be used to create and save a contact to disc:

  1. Instantiate a new object of the MapiContact class.
  2. Enter information related to various properties of the contact.
  3. Add photo data to the contact, if any.
  4. Save the contact as MSG or VCard format.


 MapiContact contact = new MapiContact("Sebastian Wright", "");

contact.setNameInfo(new MapiContactNamePropertySet("Bertha", "A.", "Buell"));

contact.setProfessionalInfo(new MapiContactProfessionalPropertySet("Awthentikz", "Social work assistant"));


contact.getPhysicalAddresses().getWorkAddress().setAddress("Im Astenfeld 59 8580 EDELSCHROTT");

contact.getElectronicAddresses().setEmail1(new MapiContactElectronicAddress("Experwas", "SMTP", ""));

contact.setTelephones(new MapiContactTelephonePropertySet("06605045265"));

// Set Photo Data

File fi = new File(dataDir + "Aspose.jpg");

byte[] fileContent = Files.readAllBytes(fi.toPath());

MapiContactPhoto photo = new MapiContactPhoto(fileContent, MapiContactPhotoImageFormat.Jpeg);


// Save as MSG + "contact.msg", ContactSaveFormat.Msg);

// Loading MSG

MapiMessage msg = MapiMessage.fromFile(dataDir + "contact.msg");

MapiContact mapiContact = (MapiContact)msg.toMapiMessageItem();

Download Running Code

Download Sample Code