Last active
April 27, 2021 21:04
-
-
Save aspose-com-gists/1d5dbf0eb9b255417cefc38475b16b91 to your computer and use it in GitHub Desktop.
Working with Outlook MSG and VCF Contacts using C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Examples for working with Outlook MSG and VCF Contacts using C++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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