img img img img img  
Home Development Partners Resellers About  
img   img The Messaging API is a COM-like API that provides access to the contents of messaging stores. "Extended MAPI in Delphi" is a package providing access to Outlook-compatible objects through a COM-based API. Using MAPI, a program can connect to a MAPI store, and then perform operations against that store.
img Extended MAPI in Delphi

Extended MAPI in DELPHI Examples (page 2)

img Example # 4
Writing a small Hierarchy Viewer

So far in the previous examples we learned how to connect to Exchange Server, how to display our Properties in Address Book, to obtain the GAL contents, and see the embedded containers.
We learned how to work with Content and Hierarchy Table, as well as with basic interfaces.

Now we will try to include all this in one example that will be a GAL Viewer. In this example we will write small GAL Hierarchy Viewer. What should do it:

- show GAL
- show Hierarchy
- show Organization
- show Organization default properties
- show Sites
- show it properties
- show Containers in each Site
- show it properties
- show recipients in each container
- show default properties for each recipient.

as Compiled Application

Source Code: In package

img Example # 5
Log in Microsoft Exchange Server/Outlook and Getting Exchange Private Store Tree

In the previous examples we focused our attention to working with GAL.
In the following several examples we will study Message Store.

Message Store stores the e-mails and other user information.
Message Store is organized as hierarchical system and its architecture "repeats" the file system.

The message store is implemented in multiple levels, with containers called folders holding messages of different types. There is no limit to the number of levels in a message store; folders can contain many subfolders.

Client application users can access a summary view of the messages contained within
each folder or view them individually with a form.

Message store data can be used in a variety of ways. Besides the traditional electronic mail usage, folders can be used as a forum for public discussion, as a repository for reference documents.

Each Message store must contain a special folder called Root. When you start Outlook for the first time, it will create in the Root folder several special folders - "Top of Personal Folders", "Search Root", that contain Custom and Default View.

All folders you can see in Outlook, such as Inbox, Outbox, Sent Items, Deleted Items, Calendar are in "Top of Personal Folders".
They are known as IPM subtree (interpersonal message subtree)....

In this example we will write small Exchange Private Store (mailbox) Hierarchy Viewer.
How to:
  • Open Mailbox
  • Find Exchange Private Store
  • Open Exchange Private Store
  • Open Store From Guid
  • Work with IMsgStore
  • Use IMAPIFolder
  • Find 'Top of Information Store'
  • Enumerate IPM Subtree
  • etc..

Example05EM as Compiled Application

Source Code: In package
img Example # 6
Getting Exchange Mailbox and enumerate items (messages) in each folder

In the preceding example we saw the structure (tree) of our MailBox. Now we will try to show the contents of each folder.

Most people think of e-mails as messages.
However, MAPI perceives each element in a folder as a message. The calendar, letters, contacts - all these are messages of different classes. But we will discuss this later.

Now, let's get to what we want to do - visualize the contents of a folder. When we select a folder in the MailBox, we will show its contents in the right-hand window. This task will be performed by the EnumThisFolder function....
How to:
  •  Enumerate messages in MAPI Folder
  •  Get Message Subject
  •  How to get Message properties
  •  etc..

Example06EM as Compiled Application

Source Code: In package
img Example # 7
Now, we will get a message from folder and...

In this example we'll not only show the contents of a folder,
but we will also be able to open each element in it.
Since MAPI perceives each entry in the Content Table as a Message,
we will not take into consideration the Message object class.
How to:
  •  Get Message class (ex. IPM.Note, IPM.Contact, IPM.Task....)
  •  Get Message Subject
  •  Get some other message properties
  •  Get Message BODY
  •  Get Attachment table
  •  Enumerate Attachments
  •  Get embedded attachment (ex: Microsoft Word Document)
  •  Get  ICON of embedded attachment
  •  ...

Example07EM as Compiled Application

Source Code: In package

img Example # 8
How to create AdviseSink to message store (Event Notification in MAPI)

The purpose of this example is to show the possible ways to get notification, when an event occurs with our Mailbox Store. E.g. a new e-mail receipt, deleting, changing objects, etc.

Why do we need this?
Sometimes the incoming messages have to be stored as archive, e.g. in SQL DataBase, by a defined property - sender, message subject, words in the e-mail text.
This may be performed automatically namely in this manner.
In other cases, when we have an incoming e-mail, its contents or part of it will be redirected to another outlet - e.g. SMS* gateway, or FAX Service.
Or, you have to update your TlistView when a MAPI object has been deleted, changed, copied, created.
For this purpose MAPI provides an IMAPIAdviseSink interface as well as several functions for the creation of an AdviseSink object and for its attachment to the MAPI SubSystem.

In the general case the AdviseSink object is attached to MAPI tables and traces the occurrence of any of the following events:

- fnevCriticalError - A global error has occurred, such as a session shut down in progress.
- fnevNewMail - A message has been delivered to the appropriate receive folder for the message class and is waiting to be processed
- fnevObjectCreated - A MAPI object has been created
- fnevObjectDeleted - A MAPI object has been deleted
- fnevObjectModified - A MAPI object has changed
- fnevObjectCopied - A MAPI object has been copied
- fnevSearchComplete - A search operation has finished and the results are available
- fnevTableModified - Information in a table has changed
- fnevExtended - An internal event defined by a particular service provider has occurred

When an event occurs, the MAPI Subsystem informs the AdviseSink object via its "callback" function IMAPIAdviseSink.OnNotify

We will build our own COM object that implements IMAPIAdviseSink, we will inform the COM subsystem of its presence upon starting the program, and we will connect to MsgStore and monitor for a new message.

The Delphi code that performs this is in the IMIMailNotifier.pas file.
We have implemented in it

TMAPIAdviseSink = class (TCOMObject, IMAPIAdviseSink)
TMailNotifier = class (TObject)

The code that we will implement is based on COM technologies and the IMAPIAdviseSink object, and it eliminates any usage of TTimer components.

If used profile is connected to Exchange Server, you no need to start the Outlook.
If you use IMO (internet mode only) Outlook, then Outlook, should be running (somebody should receive e-mails).

  • Implements an Advise method to receive notification registrations.
  • Implements an Unadvise method to receive notification cancellations.
  • Generates notifications of the appropriate type to the appropriate advise sink objects that have registered by calling their IMAPIAdviseSink.OnNotify methods.
  • Implementing Advise Sink Object
Example08EM as Compiled Application

Source Code: In package
img Example # 9
How to work with MAPI Profiles

[Original C++ code is written by Sam Charchi Microsoft Developer Support
see SAMPLE: Profman2.exe - MAPI Profile Manager v2.0]

This sample, Profman v2.0, was created to demonstrate how to use the MAPI interfaces and methods that pertain to the manipulation and creation of MAPI profile. Example is based on Microsoft Profman 2.0 Application.

In this example whose original C code is written by Microsoft you may study the original Microsoft technology of writing. We tried to stay as close as possible to the original code, however, at the points where we couldn't stand it any longer, we used DELPHI techniques.
We have left the original comments of the Microsoft developers. Its functionality is as follows:

1. Creates a new blank profile.
2. Adds services to a profile.
3. Deletes services from a profile.
4. Lists the services in a profile.
5. Adds providers to a service.
6. Deletes providers from a service.
7. Lists the providers in a service.
8. Lists the available properties of a service (even those that are normally inaccessible).
9. Lists the available properties of a provider (even those that are normally inaccessible).

as Compiled Application

Source Code: In package

img Example # 10
How to allow users to change their profile details on the exchange server

In this example we will go back to GAL for a short while.

In many cases, the Exchange Server administrators do not have the time to fill in all fields describing the users, such as Address, City, State, Zip Code, Country, Title, Company, Department, Office, Assistant...

This may be performed successfully using MAPI.
For this purpose we need to take an interface to the user that is listed in GAL.
To this end most convenient is IMAPIProp, since IMailUser and IDistList implement IMAPIProp.

Once you compile this program, you may provide it to all users so they can update their ID data themselves.

To update their attributes, users need to have special rights.
We will try to go round them, however, if you get a message that you do not have the right to do this, or that you do not have sufficient rights, you may do the following procedure as described in "XADM: How to Use the GAL Modify Tool"

Allow users to change:
  • Address
  • City
  • State
  • Zip Code
  • Country
  • Title
  • Company
  • Department
  • Office
  • Assistant
  • Phone

as Compiled Application

Source Code: In package

img The Next Extended MAPI in Delphi Examples
Copyright © 2021 IMIBO
Privacy Statement