O'Reilly logo

CDO & MAPI Programming with Visual Basic: by Dave Grundgeiger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 to True. 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. The ProfileName parameter is ignored if the ProfileInfo parameter is supplied.

ProfilePassword ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required