%
' AnonLogin.inc. VBScript methods to create and check an ActiveMessaging session
'
'============================
' ReportError
'
'============================
Function ReportError( bstrContext)
ReportError= False
If Err.Number <> 0 Then
Response.Write( "Error: " & bstrContext & " : " & Err.Number & ": " & Err.Description & "
")
Err.Clear
ReportError= True
End If
End Function
'============================
' CheckAMSession
'
' Checks for and returns the AM session in the Sesion object. If not found,
' calls NoSession().
' Call this before emiting any HTML or any redirects, authentication, etc. may not work.
' Returns: True if session exists or can be created
'============================
Public Function CheckAMSession
On Error Resume Next
Dim amSession
CheckAMSession= False
Set amSession= Session( "AMSession")
If amSession Is Nothing Then
NoSession
Set amSession= Session( "AMSession")
End If
If Not amSession Is Nothing Then
CheckAMSession= true
End If
End Function
'============================
' NoSession
'
' Called when the AM session can not be found. Either creates a session or gets
' more info from the user. Returns only if the session was created.
'============================
Sub NoSession
On Error Resume Next
Dim strLogonID
Dim bstrServer
Dim bstrMailbox
Dim bstrProfileInfo
Dim objAMSession1
Dim objRenderApp
Dim objInbox
' must be authenticated to sucessfully logon
BAuthenticateUser
Err.Clear
Set objAMSession1 = Server.CreateObject("MAPI.Session")
If Not ReportError( "create MAPI.Session") Then
set objRenderApp = Application( "RenderApplication" )
' Construct the ActiveMessaging profile from server and mailbox name
'Set bstrServer equal to an exchange server on the same site as the expected user
bstrServer = "localhost"
'Since you are logging on using "Allow Anonymous" you must set the mailbox that
'you intend to use. You can not find the userID from ServerVariables("LOGON_USER")
'because that will return an empty string
bstrMailbox = "webmail"
bstrProfileInfo = bstrServer + vbLF + bstrMailbox
response.write("bstrProfileInfo = " & bstrProfileInfo & "
")
Err.Clear
objAMSession1.Logon "", "", False, True, 0, True, bstrProfileInfo
If Not ReportError( "ActiveMessaging Logon") Then
' To ensure that we are really logged on, we need to try retrieving
' some data.
Err.Clear
Set objInbox = objAMSession1.Inbox
If ReportError( "Get Inbox") Then
' The logon is no good. We'll do a little cleanup here.
objAMSession1.Logoff
Set objAMSession1 = Nothing
End If
' This will be retrieved back up in CheckSession
' Note that if the logon failed this is set to 'Nothing'
Set Session("AMSession") = objAMSession1
' Need this to recreate the proper security context in Session_OnEnd
Session("hImp") = objRenderApp.ImpID
End If 'objAMSession1.Logon
End If 'Server.CreateObject()
End Sub
%>