Establishing a Session

All technologies based on MAPI, as Simple MAPI is, require that a MAPI session be established prior to sending and receiving messages. MAPI sessions were explained in Chapter 2. To establish a MAPI session using Simple MAPI, call the MAPILogon function, as shown here:

Dim nMAPISession As Long

' Initiate a MAPI session.
nRetVal = MAPILogon(0, "MyProfile", "", MAPI_NEW_SESSION, _
   0, nMAPISession)

The MAPILogon function has several parameters. Its Declare statement looks like this:

Public Declare Function MAPILogon Lib "MAPI32.DLL" ( _
   ByVal UIParam As Long, _
   ByVal User As String, _
   ByVal Password As String, _
   ByVal Flags As Long, _
   ByVal Reserved As Long, _
   Session As Long _
) As Long

The parameters to the MAPILogon function are:

UIParam

The handle of the window that is to be considered the parent of any dialog boxes displayed by MAPI during logon.

Depending on the values passed in the User and Flags parameters, MAPI may need to display a logon dialog box. Pass the hWnd property of a form to make that form the parent window. Pass a to indicate that any dialog boxes should be application-modal. If no dialog box is displayed during logon, UIParam is ignored.

User

This is the name of the profile that is to be used for the session. (MAPI profiles were explained in Chapter 2.) To cause MAPI to prompt the user for a profile to use, pass an empty string in the User parameter and specify the MAPI_LOGON_UI flag in the Flags parameter.

Password

Always pass an empty string ...

Get CDO & MAPI Programming with Visual Basic: now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.