This example shows how to fetch mail from the server.We initialize MAPI library with the profiles database path, retrieve the default profile name and open connections to both the Exchange message store provider (EMSMDB) and Exchange Address Book provider (EMSABP).
Now we have opened a connection to the Exchange message store provider, we can open the user mailbox store with OpenMsgStore() This function will return a set of pre-defined folder unique IDs (stored on double values) and a pointer to the upper object we can access in MAPI hierarchy.
We now open the Inbox folder. Since OpenMsgStore() returns a set of common folders identifiers we store in the message store object (obj_store), we can retrieve them using the convenient GetDefaultFolder() function. This function doesn't generate any network traffic, but returns the folder identifier associated with the constant passed as argument (here olFolderInbox).
We could have used MAPI tables and GetHierarchyTable() function to find Inbox folder identifier. We would have had to retrieve the Top Information Store hierarchy table, customize the view with PR_FID (Folder ID MAPI property) and PR_DISPLAY_NAME, find the IPM_SUBTREE folder identifier, open it, retrieve the Hierarchy Table, call SetColumns() with PR_FID and finally browse table rows until we found the Inbox folder.folders to store emails within IPM_SUBTREE folder hierarchy.
Once the Inbox folder is opened, we can call GetContentsTable() to create the view needed to list all the children objects. In the current example we suppose we will only retrieve IPM.Post objects (emails).
We now customize the MAPI view and set the columns with the property tags we want to access: PR_FID (Folder Identifier) and PR_MID (Message identifier). MAPI uses unique and permanent identifiers to classify objects. These identifiers are double values (8 bytes) and never change until you move the object to another location.
We now enter the last step of the fetching process:
We finally release mapi objects and clean up the MAPI library before returning
![]() ![]() ![]() |
This content is licensed under the Creative Commons Attribution ShareAlike License v. 3.0: http://creativecommons.org/licenses/by-sa/3.0/ |