Read and Convert Outlook OST File
Read and Convert Outlook OST File
Outlook keeps mail of POP3 and IMAP accounts in a PST file, while for Microsoft Exchange and Microsoft 365 accounts it maintains an OST file - an offline copy of the server mailbox. Both files share the same internal structure, so Aspose.Email for C++ opens either of them with the PersonalStorage class and exposes the same folders, messages and other items.
The samples in this article use these headers and namespaces:
#include <Storage/Pst/PersonalStorage.h>
#include <Storage/Pst/FileFormat.h>
#include <Storage/Pst/FolderInfo.h>
#include <Storage/Pst/FolderInfoCollection.h>
#include <Storage/Pst/StandardIpmFolder.h>
#include <system/convert.h>
#include <system/object_ext.h>
using namespace System;
using namespace Aspose::Email::Storage::Pst;
Reading OST Files
No special API is needed for an OST file: pass its path to PersonalStorage::FromFile and work with the returned storage exactly as with a PST file. PersonalStorage::get_Format reports which of the two formats was opened, as a FileFormat value.
The top level of an OST file holds the service folders of the Exchange mailbox, so the standard folders are easier to reach by their role with GetPredefinedFolder than by walking the tree from the root.
SharedPtr<PersonalStorage> ost = PersonalStorage::FromFile(u"Outlook.ost", false);
Console::WriteLine(u"Storage format: " + ObjectExt::ToString(ost->get_Format()));
for (SharedPtr<FolderInfo> folder : ost->get_RootFolder()->GetSubFolders())
{
Console::WriteLine(u"Top-level folder: " + folder->get_DisplayName());
}
SharedPtr<FolderInfo> inbox = ost->GetPredefinedFolder(StandardIpmFolder::Inbox);
Console::WriteLine(inbox->get_DisplayName() + u": " + Convert::ToString(inbox->get_ContentCount()) + u" items");
ost->Dispose();
Converting OST to PST
An OST file is bound to the Outlook profile that synchronized it and cannot be opened in Outlook on another computer. To move its contents elsewhere, save the storage as a PST file with PersonalStorage::SaveAs, passing the target path and FileFormat::Pst. The source file stays unchanged.
SharedPtr<PersonalStorage> ost = PersonalStorage::FromFile(u"Outlook.ost", false);
ost->SaveAs(u"ConvertedFromOst.pst", FileFormat::Pst);
ost->Dispose();
// the result is an ordinary PST file
SharedPtr<PersonalStorage> pst = PersonalStorage::FromFile(u"ConvertedFromOst.pst", false);
Console::WriteLine(u"Converted storage format: " + ObjectExt::ToString(pst->get_Format()));
SharedPtr<FolderInfo> inbox = pst->GetPredefinedFolder(StandardIpmFolder::Inbox);
Console::WriteLine(inbox->get_DisplayName() + u": " + Convert::ToString(inbox->get_ContentCount()) + u" items");
pst->Dispose();