Sending or Receiving a Message on Demand
Clients typically rely on the MAPI subsystem — the MAPI spooler and the service providers — to handle the timing of message transmission and reception. However, you can alter this timing by using the status object of either the MAPI spooler or a transport provider. The IMAPIStatus::FlushQueues method removes all messages from one or more transport provider's incoming or outgoing queues. The following procedures describe two techniques for sending or receiving messages on demand. The first procedure uses the MAPI spooler's status object to flush the queues of every transport provider in the profile; the second procedure flushes the queue of a single transport provider.
To flush all incoming or outgoing queues in a single operation
-
Call IMAPISession::GetStatusTable to access the status table.
-
Call the status table's IMAPITable::SetColumns method to limit the column set to PR_ENTRYID and PR_RESOURCE_TYPE.
-
Build a property restriction using an SPropertyRestriction structure to match PR_RESOURCE_TYPE with MAPI_SPOOLER.
-
Call HrQueryAllRows, passing in the SPropertyRestriction structure, to retrieve the row that represents the status of the MAPI spooler.
-
Pass the PR_ENTRYID column to IMAPISession::OpenEntry to open the MAPI spooler's status object.
-
Call the MAPI spooler's IMAPIStatus::FlushQueues method, passing the FLUSH_NO_UI flag to suppress the user interface and either the FLUSH_DOWNLOAD or FLUSH_UPLOAD flag to flush the outgoing or incoming queues.
-
Release the status object and the status table, as well as the SRowSet structure that is allocated for the table.
To flush incoming or outgoing queues individually by transport provider
-
Call IMAPISession::GetStatusTable to access the status table.
-
Call the status table's IMAPITable::SetColumns method to limit the column set to PR_ENTRYID and PR_RESOURCE_TYPE.
-
Build a property restriction using an SPropertyRestriction structure to match PR_RESOURCE_TYPE with MAPI_TRANSPORT_PROVIDER.
-
Call HrQueryAllRows, passing in the SPropertyRestriction structure, to retrieve the rows that are supplied by transport providers.
-
For each row returned from HrQueryAllRows:
-
Pass the PR_ENTRYID column to IMAPISession::OpenEntry to open the transport provider's status object.
-
Check that the transport status object supports the FlushQueues method by checking that its PR_RESOURCE_METHODS property has the STATUS_FLUSH_QUEUES flag set.
-
If supported, call IMAPIStatus::FlushQueues. If unsupported, call the MAPI spooler's IMAPIStatus::FlushQueues method, passing the entry identifier of the transport in the lpTargetTransport parameter. See the preceding procedure for instructions on accessing the MAPI spooler's status object. Set the FLUSH_DOWNLOAD flag to flush the outgoing queues or the FLUSH_UPLOAD flag to flush the incoming queues.
-
Release the status object and the status table, as well as the SRowSet structure that is allocated for the table.
The MAPI spooler honors the FLUSH_NO_UI flag as do most LAN transport providers. However, not all transport providers honor this flag, particularly those that use a modem explicitly and the Remote Access Service (RAS). RAS was not designed to allow clients to suppress the user interface. It is possible for a client to be configured so that it can connect without requiring the interaction of a user, but it is difficult and requires intimate knowledge of the client's message services.