Establishing a Session
The first step in working with
MAPI, regardless of which access methodology is used, is to establish
a MAPI session. In CDO, this is done with the Session object’s
Logon method. The sample application declares a single Session object
with global scope in Globals.bas
:
Public gCdoSession As MAPI.Session
If
you’re relatively new to Visual Basic, recall that this
declaration doesn’t actually create a Session object, it merely
declares a variable that is capable of referring to such an object.
The object itself is created by this code in subroutine
tmrOpenCdoSession_Timer
, found in
frmMain
:
' Instantiate a new session object and logon. Set gCdoSession = New MAPI.Session gCdoSession.Logon
The Logon method accepts a number of parameters, all of which are optional. Here is the syntax:
CdoSession.Logon([ProfileName
][,ProfilePassword
][,ShowDialog
][,NewSession
] [,ParentWindow
][,NoMail
][,ProfileInfo
])
The parameters are:
-
ProfileName
A string that specifies the name of the profile to use for the MAPI session. To cause the MAPI subsystem to prompt the user for the profile name, set this parameter to an empty string and set the
ShowDialog
parameter toTrue
. These are the default settings for these parameters, so omitting them both has the same effect. Alternatively, the user’s profile names and default profile name can be read from the registry, as explained in Chapter 2. TheProfileName
parameter is ignored if theProfileInfo
parameter is supplied.-
ProfilePassword ...
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.