DOCX JPG PDF XML PST
  Product Family
MSG

Convert PST to MSG in C++

High performance PST to MSG conversion using C++ Email library.

How to Convert PST to MSG Using C++

In order to convert PST to MSG, we’ll use

Aspose.Email for C++

API which is a feature-rich, powerful and easy to use document manipulation and conversion API for C++ platform. You can download its latest version directly, just open

NuGet

package manager, search for Aspose.Email.Cpp and install. You may also use the following command from the Package Manager Console.

Command

PM> Install-Package Aspose.Email.Cpp

Steps to Convert PST to MSG via C++

C++ programmers can easily convert PST file to MSG in just a few lines of code.

  • Load PST file with PersonalStorage::FromFile.
  • Call the SaveAs() method having two parameters.
  • Output MSG file and FileFormat::Msg as parameters.
  • MSG file will be saved at the specified path.
  • Open MSG file in compatible program.

System Requirements

Before running the C++ conversion code, make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with C++ Runtime Environment for Windows 32 bit, Windows 64 bit and Linux 64 bit.
  • Aspose.Email for C++ DLL referenced in your project.
 

Convert PST to MSG - C++

// Load the Outlook PST file
System::SharedPtr<PersonalStorage> personalStorage = PersonalStorage::FromFile(dataDir + L"SampleContacts.pst");
// Get the Contacts folder
System::SharedPtr<FolderInfo> folderInfo = personalStorage->get_RootFolder()->GetSubFolder(L"Contacts");
// Loop through all the contacts in this folder
System::SharedPtr<MessageInfoCollection> messageInfoCollection = folderInfo->GetContents();
    
{
    auto messageInfo_enumerator = (messageInfoCollection)->GetEnumerator();
    decltype(messageInfo_enumerator->get_Current()) messageInfo;
    while (messageInfo_enumerator->MoveNext() && (messageInfo = messageInfo_enumerator->get_Current(), true))
    {
        // Get the contact information
        System::SharedPtr<MapiMessage> mapi = personalStorage->ExtractMessage(messageInfo);
        
        System::SharedPtr<MapiContact> contact = System::DynamicCast<Aspose::Email::Outlook::MapiContact>(mapi->ToMapiMessageItem());
        
        // Save to disk in MSG format
        if (contact->get_NameInfo()->get_DisplayName() != nullptr)
        {
            System::SharedPtr<MapiMessage> message = personalStorage->ExtractMessage(messageInfo);
            // Get rid of illegal characters that cannot be used as a file name
            System::String messageName = message->get_Subject().Replace(L":", L" ").Replace(L"\\", L" ").Replace(L"?", L" ").Replace(L"/", L" ");
            message->Save(dataDir + L"Contacts\\" + messageName + L"_out.msg");
        }
    }
}  
 
  • PST to MSG Conversion Live Demos

    Other Supported Conversions

    You can also convert PST into many other file formats including few listed below.

    PST TO EML (Outlook Email Messages)
    PST TO EMLX (Apple EMLX Format)
    PST TO HTML (Hyper Text Markup Language)
    PST TO ICS (iCalendar)
    PST TO MBOX (Electronic Mail Messages)
    PST TO MHTML (Web Page Archive Format)
    PST TO OFT (Outlook Email Templates)
    PST TO OST (Offline Storage Files)
    PST TO VCF (Virtual Card Format)