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 MAPI Session

Example 11-5 shows a complete ASP page for creating a CDO Session object and logging on to Exchange Server. Note that this and subsequent examples assume the existence of the global.asa file shown in Example 11-4.

Example 11-5. Establishing a MAPI Session

<!-- #include file="lib.inc" --> <% ' ----------------------------------------------------------------- ' logon.asp ' This page establishes a MAPI session. ' ----------------------------------------------------------------- Dim strUsername Dim strProfileInfo Dim CdoSession Dim CdoFolder Dim CdorlApplication ' Make sure that the user is authenticated. If Request.ServerVariables("AUTH_USER") = "" Then Response.Status = "401 Unauthorized" Response.AddHeader "WWW-Authenticate", "Basic" Response.End End If ' Get the username. strUsername = Request.ServerVariables("AUTH_USER") ' Get the CDORL Application object. This will be used for obtaining ' the security context after logging on to MAPI. Set CdorlApplication = Application.Contents("CdorlApplication") ' Create a CDO Session object. Set CdoSession = Server.CreateObject("MAPI.Session") ' Save the CDO Session object for later use. Set Session.Contents("CdoSession") = CdoSession ' Log on to MAPI. strProfileInfo = "MyExchangeServer" & vbLf & strUsername CdoSession.Logon , , False, True, , , strProfileInfo ' Save the security context. Session.Contents("hImp") = CdorlApplication.ImpID ' The Logon method always succeeds, so try to access something to ' ensure ...

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