_NameSpace.Logon(Object, Object, Object, Object) Method

Definition

Logs the user on to MAPI, obtaining a MAPI session.

public void Logon (object Profile, object Password, object ShowDialog, object NewSession);
Public Sub Logon (Optional Profile As Object, Optional Password As Object, Optional ShowDialog As Object, Optional NewSession As Object)

Parameters

Profile
Object

The MAPI profile name, as a String (string in C#), to use for the session. Specify an empty string to use the default profile for the current session.

Password
Object

The password (if any), as a String (string in C#), associated with the profile. This parameter exists only for backwards compatibility and for security reasons, it is not recommended for use. Microsoft Outlook will prompt the user to specify a password in most system configurations. This is your logon password and should not be confused with PST passwords.

ShowDialog
Object

True to display the MAPI logon dialog box to allow the user to select a MAPI profile.

NewSession
Object

True to create a new Outlook session. Since multiple sessions cannot be created in Outlook, this parameter should be specified as True only if a session does not already exist.

Remarks

Use the Logon method only to log on to a specific profile when Outlook is not already running. This is because only one Outlook process can run at a time, and that Outlook process uses only one profile and supports only one MAPI session. When a user start Outlook a second time, that instance of Outlook runs within the same Outlook process, does not create a new process, and uses the same profile.

If Outlook is already running, using this method does not create a new Outlook session or change the current profile to a different one.

If Outlook is not running and you only want to start Outlook with the default profile, do not use the Logon method. A better alternative is shown in the following code example InitializeMAPI: first, instantiate the Outlook Application object, then reference a default folder such as the Inbox. This has the side effect of initializing MAPI to use the default profile and to make the object model fully functional.

Imports Outlook = Microsoft.Office.Interop.Outlook

Sub InitializeMAPI ()

    ' Start Outlook.
    Dim olApp As Outlook.Application
    Set olApp = CreateObject("Outlook.Application")

    ' Get a session object. 
    Dim olNs As Outlook.NameSpace
    Set olNs = olApp.GetNamespace("MAPI")

    ' Create an instance of the Inbox folder. 
    ' If Outlook is not already running, this has the side
    ' effect of initializing MAPI.
    Dim mailFolder As Outlook.Folder
    Set mailFolder = olNs.GetDefaultFolder(olFolderInbox)

    ' Continue to use the object model to automate Outlook.
End Sub

Starting in Outlook 2010, if you have multiple profiles, you have configured Outlook to always use a default profile, and you use the Logon method to log onto the default profile without prompting the user, the user will receive a prompt to choose a profile anyway. To avoid this behavior, do not use the Logon method; use the workaround suggested in the preceding InitializeMAPI example instead.

Applies to