Share via


_NameSpace.Logon Method

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

Namespace:  Microsoft.Office.Interop.Outlook
Assembly:  Microsoft.Office.Interop.Outlook (in Microsoft.Office.Interop.Outlook.dll)

Syntax

'Declaration
<DispIdAttribute()> _
Sub Logon ( _
    Profile As Object, _
    Password As Object, _
    ShowDialog As Object, _
    NewSession As Object _
)
'Usage
Dim instance As _NameSpace
Dim Profile As Object
Dim Password As Object
Dim ShowDialog As Object
Dim NewSession As Object

instance.Logon(Profile, Password, ShowDialog, _
    NewSession)
[DispIdAttribute()]
void Logon(
    Object Profile,
    Object Password,
    Object ShowDialog,
    Object NewSession
)

Parameters

  • Profile
    Type: System.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
    Type: System.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 Oultook 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
    Type: System.Object

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

  • NewSession
    Type: System.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.

See Also

Reference

_NameSpace Interface

_NameSpace Members

Microsoft.Office.Interop.Outlook Namespace

Other Resources

How to: Get and Log On to an Instance of Outlook