JerryHolder
asked on
Logging into Exchange programmatically with VB
Are there 3 steps to success for using VB to automatically and programatically log into an Exchange Srevre with a valid account and password?
When tried, the login dialog is thrown indicating the correct login/domain but wants to know the password.
Below is the function in VB. Apprciate any and all comments/help
Private Function ACMISLogon() As Boolean
ACMISLogon = False
' Create Recordset Object named rsUnread
CreateRS
' If a session is already started,
' exit sub.
If bnewsession = False Then
If mpsSess.NewSession Then
MsgBox "Session already established"
Exit Function
End If
End If
On Error GoTo errLogInFail
With mpsSess
.UserName = "XXXX"
.Password = "cmc"
.LogonUI = True ' Use the underlying email system's logon UI.
.SignOn ' Signon method.
' If successful, return True
ACMISLogon = True
' Set NewSession to True and set0
' variable flag to true
.NewSession = True
bnewsession = .NewSession
mpmMess.SessionID = .SessionID ' You must set this before continuing.
sbrMapi.Panels("SessID") = "ID = " & .SessionID ' Just so you can see the SessionID.
End With
On Error GoTo 0
Exit Function
errLogInFail:
Debug.Print Err.Number, Err.Description
If Err.Number = 32003 Then
MsgBox "Canceled Login"
ACMISLogon = False
End If
Exit Function
End Function
When tried, the login dialog is thrown indicating the correct login/domain but wants to know the password.
Below is the function in VB. Apprciate any and all comments/help
Private Function ACMISLogon() As Boolean
ACMISLogon = False
' Create Recordset Object named rsUnread
CreateRS
' If a session is already started,
' exit sub.
If bnewsession = False Then
If mpsSess.NewSession Then
MsgBox "Session already established"
Exit Function
End If
End If
On Error GoTo errLogInFail
With mpsSess
.UserName = "XXXX"
.Password = "cmc"
.LogonUI = True ' Use the underlying email system's logon UI.
.SignOn ' Signon method.
' If successful, return True
ACMISLogon = True
' Set NewSession to True and set0
' variable flag to true
.NewSession = True
bnewsession = .NewSession
mpmMess.SessionID = .SessionID ' You must set this before continuing.
sbrMapi.Panels("SessID") = "ID = " & .SessionID ' Just so you can see the SessionID.
End With
On Error GoTo 0
Exit Function
errLogInFail:
Debug.Print Err.Number, Err.Description
If Err.Number = 32003 Then
MsgBox "Canceled Login"
ACMISLogon = False
End If
Exit Function
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.