Logging In To A MAPI Session

Prior to working with MAPI, you must sign in and allow the system to validate your password, if you've assigned one. When you use the MAPI logon function, you specify several different things. These include whether to display the standard user ID and password box and what variable you need to assign the session to.

As you work with MAPI, you do so in a "session." The login process will return a session ID that you will refer to as you submit or retrieve messages. The general format of a basic implementation of the logon is:


MAPILogon(0&, "", "", MAPI_LOGON_UI, 0&, gMAPISession)

gMAPISession will be established with the new session ID in this case. It should be declared as a global variable so that your other routines can refer to it if necessary.

When you make the call, be sure to check the return status for SUCCESS_SUCCESS. The samples included for this session have the constants definition files provided by Microsoft and can be included in your application for easy reference.

When you specify "MAPI_LOGON_UI" in the call, MAPI will automatically display the familiar logon screen. This allows the user to specify the user name and password for the mail system and will use this information to establish the mail session.

MAPI Logon Dialog Box

Be sure to put some error handling logic in your routines. If you will simply show the returned error code and a message indicating a problem, you should be able to provide the user with another chance to sign in. MAPI will also display an error message prior to returning to your application, generally providing good feedback to the user about what the problem is.