Contacts are an essential part of any email client as they facilitate the user by remembering all their contacts, similar to the contacts on your smartphone. Outlook contacts store a lot of information regarding a person, such as their name, address, contact number, email address, etc. These contacts can be stored in MSG and VCF formats. You might find yourself in scenarios where you need to create or alter MSG or VCF contacts programmatically. For that, this article will teach you how to work with MSG and VCF contacts using C++.
- C++ API for Working with MSG and VCF Contacts
- Create MSG and VCF Contacts
- Read MSG and VCF Contacts
- Modify MSG and VCF Contacts
- Get a Free License
C++ API for Working with MSG and VCF Contacts
Aspose.Email for C++ is a native C++ library for creating, manipulating, and sending emails without requiring Microsoft Outlook to be installed. The API also supports working with contacts and calendars. You can either install the API through NuGet or download it directly from the Downloads section.
PM> Install-Package Aspose.Email.Cpp
Create MSG and VCF Contacts
In this section, you will learn how to create an Outlook contact and save it in MSG and VCF format. The following are the steps to achieve that.
- Create an instance of the MapiContact class.
- Set the properties of the contact such as the Name, Address, Telephone, etc.
- Save the contact using the MapiContact->Save(System::String filePath, Aspose::Email::Mapi::ContactSaveFormat saveFormat) method.
The following sample code demonstrates how to create an Outlook contact and save it in MSG and VCF format using C++.
Read MSG and VCF Contacts
Aspose.Email for C++ supports reading contacts in both MSG and VCF formats. Here, you will see how to open MSG and VCF contacts using C++.
Read MSG Contact
The following are the steps to read an MSG contact.
- Load the contact using the MapiMessage class.
- Convert MapiMessage to IMapiMessageItem using the MapiMessage->ToMapiMessageItem() method and cast it to MapiContact.
- Read the properties of the contact.
The following is the sample code to read an MSG contact using C++.
Open VCF Contact
To read a VCF contact, simply load the contact using the MapiContact::FromVCard method. The following sample code shows how to read a VCF contact using C++.
Modify MSG and VCF Contacts
In order to modify an MSG/VCF contact, open the contact as demonstrated in the previous section and then change its properties. The following are the steps to modify contacts.
- Load the MSG/VCF contact as shown in the Read MSG and VCF Contacts section.
- Change the desired properties of the contact.
- Save the contact using the MapiContact->Save(System::String filePath, Aspose::Email::Mapi::ContactSaveFormat saveFormat) method.
The following sample code demonstrates how to modify MSG/VCF contacts using C++.
Get a Free License
You can try the API without evaluation limitations by requesting a free temporary license.
Live Demo
Conclusion
In this article, you have learned how to work with MSG and VCF contacts using C++. Specifically, you have learned how to create, read and modify contacts using Aspose.Email for C++ API. The API provides a bunch of additional features for automating your email-related tasks. You can explore the API in detail by visiting the official documentation. If you have any questions, please feel free to reach us on our free support forum.