How to get emails from MS Outlook PST file(in MSG format).

with using Extended Messaging API or using Mailbox SDK API.

Note:
The MSG format is closed. Email saved in MSG files are a repository flows, to work with the data flow can be using the IStream interface. Email in the MSG format does not contain a full copy of the RFC email.

Extended Messaging API (EMAPI).
Steps:
- Call EMAPI function MAPIInitialize (msmapi32.dll).
- Create a new profile to connect to message store causing MAPIAdminProfiles (0, IProfAdmin), after IProfAdmin.CreateProfile (NewProfileName, 0, 0, 0).
- Registered as a message service IProfAdmin.CreateMsgService (ServiceID, ProfileName, 0, ERVICE_UI_ALLOWED).

Now interface is ready for work, you need to list all the folders inside your storage (PST file):
- You need to get a root folder using the IMsgStore interface - IMsgStore.OpenEntry (0, 0, TGUID (IID_IMAPIFolder), MAPI_READ, MAPIRootFolderType, IUnknown (MAPIRootFolder)).
- After enumerate all the objects in the root folder, separate folders and objects to list objects of these objects. (use recursion).

For each ordinary found a folder you can transfer the facilities of communications inside the folder (use IMsgStore.OpenEntry). Every ordinary object you can store messages in a separate file using StgCreateDocfile, OpenIMsgSession, OpenIMsgOnIStg, IMessage.CopyTo.

Use Mailbox SDK API:


PSTHandle = OpenMailbox ( 'FullPath and PST file name' );
for FolderCount = 0 to GetFolderCount - 1 do
   GetFolderProp (PSTHandle, FolderCount, Folder);
   for MailCount = 0 to Folder.MailCount - 1 do
      GetMail (PSTHandle, FolderCount, MailCount, Mail);

In this program code is no COM objects and not fill the complex data structures.
You specify the full path and file name any PST Mailbox files.
Using Mailbox SDK API GetFolderCount you get number of folders inside the Mailbox.
Using Mailbox SDK API MailCount you get a number of emails inside folder.
Using email numbers you turn to each of them.

If you replace PST file MS Outlook, on the DBX file MS Outlook Express, you do not come to change the code, to perform the most these action.
Mailbox SDK API specifically designed for use in VS C++, C# and Delphi.