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

    ' 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
    Debug.Print Err.Number, Err.Description
    If Err.Number = 32003 Then
        MsgBox "Canceled Login"
        ACMISLogon = False
    End If
    Exit Function
End Function

Who is Participating?
Neo_mvpsConnect With a Mentor Commented:
Without seeing the SigOn method, I would have to guess that the logon method is not grabing the correct profile or the dialog will always show because of LogonUI = True.

Logon properties are:


profileName - Is the friendly name of a profile given by a user.

profilePassword - Password to access the account

showDialog - Show logon UI

newSession - should this be a newSession

parentWindow - parent window that owns this session

NoMail - Used when writing a service.  Gives the ability to send but not receive.

ProfileInfo - The Exchange Server/Mailbox name you want to access.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.