Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/1d5dbf0eb9b255417cefc38475b16b91 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/1d5dbf0eb9b255417cefc38475b16b91 to your computer and use it in GitHub Desktop.
Working with Outlook MSG and VCF Contacts using C++
Examples for working with Outlook MSG and VCF Contacts using C++
// Create an instance of the MapiContact class to represent the contact
System::SharedPtr<MapiContact> contact = System::MakeObject<MapiContact>();
// Set properties of the contact
System::SharedPtr<MapiContact> contact = System::MakeObject<MapiContact>();
contact->set_NameInfo(System::MakeObject<MapiContactNamePropertySet>(u"John", u"A.", u"Doe"));
contact->set_ProfessionalInfo(System::MakeObject<MapiContactProfessionalPropertySet>(u"Awthentikz", u"Social work assistant"));
contact->get_PersonalInfo()->set_PersonalHomePage(u"aspose.com");
contact->get_PhysicalAddresses()->get_HomeAddress()->set_Address(u"Im Astenfeld 59 8580 EDELSCHROTT");
contact->get_ElectronicAddresses()->set_Email1(System::MakeObject<MapiContactElectronicAddress>(u"test", u"SMTP", u"JohnADoe@test.com"));
contact->set_Telephones(System::MakeObject<MapiContactTelephonePropertySet>(u"06605045265"));
contact->get_PersonalInfo()->set_Children(System::MakeArray<System::String>({ u"child1", u"child2", u"child3" }));
contact->set_Categories(System::MakeArray<System::String>({ u"category1", u"category2", u"category3" }));
contact->set_Mileage(u"Some test mileage");
contact->set_Billing(u"Test billing information");
contact->get_OtherFields()->set_ReminderTime(System::DateTime(2022, 1, 1, 0, 0, 55));
contact->get_OtherFields()->set_UserField1(u"ContactUserField1");
contact->get_OtherFields()->set_UserField2(u"ContactUserField2");
contact->get_OtherFields()->set_UserField3(u"ContactUserField3");
contact->get_OtherFields()->set_UserField4(u"ContactUserField4");
// Add a photo
{
System::SharedPtr<System::IO::FileStream> fs = System::IO::File::OpenRead(u"SourceDirectory\\Desert.jpg");
System::ArrayPtr<uint8_t> buffer = System::MakeArray<uint8_t>(fs->get_Length(), 0);
fs->Read(buffer, 0, buffer->get_Length());
contact->set_Photo(System::MakeObject<MapiContactPhoto>(buffer, Aspose::Email::Mapi::MapiContactPhotoImageFormat::Jpeg));
}
// Save the contact in MSG format
contact->Save(u"OutputDirectory\\MapiContact_out.msg", Aspose::Email::Mapi::ContactSaveFormat::Msg);
// Save the contact in VCF format
contact->Save(u"OutputDirectory\\MapiContact_out.vcf", Aspose::Email::Mapi::ContactSaveFormat::VCard);
// Load the contact file
System::SharedPtr<MapiMessage> msg = MapiMessage::FromFile(u"SourceDirectory\\Contact.msg");
System::SharedPtr<MapiContact> mapiContact = System::DynamicCast<Aspose::Email::Mapi::MapiContact>(msg->ToMapiMessageItem());
// Modify contact properties
mapiContact->set_NameInfo(System::MakeObject<MapiContactNamePropertySet>(u"John", u"A.", u"Doe"));
// Save the contact
mapiContact->Save(u"OutputDirectory\\MapiContact_out.msg", Aspose::Email::Mapi::ContactSaveFormat::Msg);
// Load the contact file
System::SharedPtr<MapiMessage> msg = MapiMessage::FromFile(u"SourceDirectory\\Contact.msg");
System::SharedPtr<MapiContact> mapiContact = System::DynamicCast<Aspose::Email::Mapi::MapiContact>(msg->ToMapiMessageItem());
// Display contact information
System::Console::WriteLine(mapiContact->get_NameInfo()->get_DisplayName());
System::Console::WriteLine(mapiContact1->get_PhysicalAddresses()->get_HomeAddress()->get_Address());
System::Console::WriteLine(mapiContact->get_Telephones()->get_PrimaryTelephoneNumber());
System::Console::WriteLine(mapiContact->get_ElectronicAddresses()->get_Email1());
// Load the contact file
System::SharedPtr<MapiContact> mapiContact = MapiContact::FromVCard(u"SourceDirectory\\Contact.vcf");
// Display contact information
System::Console::WriteLine(mapiContact->get_NameInfo()->get_DisplayName());
System::Console::WriteLine(mapiContact1->get_PhysicalAddresses()->get_HomeAddress()->get_Address());
System::Console::WriteLine(mapiContact->get_Telephones()->get_PrimaryTelephoneNumber());
System::Console::WriteLine(mapiContact->get_ElectronicAddresses()->get_Email1());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment