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 ...
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.