MailBee.NET Objects 3.1

Pop3.Login Method (String, String, AuthenticationMethods, AuthenticationOptions, SaslMethod)

Logs in a mailbox on the POP3 server.

public bool Login(
   string accountName,
   string password,
   AuthenticationMethods authMethods,
   AuthenticationOptions authOptions,
   SaslMethod authUserDefined
);

Parameters

accountName
The user account name on the server.
password
The password of the user account on the server.
authMethods
A set of authentication methods which can be used when logging in a mailbox.
authOptions
Specifies the options which affect login process.
authUserDefined
A reference to the instance of user defined authentication method, or a null reference (Nothing in Visual Basic) if user defined authentication is not used.

Return Value

true if a login attempt succeeded; otherwise, false.

Remarks

By default, MailBee won't even try to use authentication methods which are not listed by the server in its capabilities. This behavior can be changed by setting TryUnsupportedMethods bit in authOptions. If, during the authentication attempt, the server reports that the method is unsupported, MailBee will try the next method in authMethods until the compatible method is found or no more methods left. This behavior can be changed by setting UseSingleMethodOnly bit in authOptions.

Authentication methods are tried from more secure to less secure. If authMethods is set to Auto and authOptions is None, MailBee will try to use the most secure method supported by the server but will downgrade to less secure methods (to the simplest USER/PASS authentication in the worst case) if better methods are not available.

Exceptions

Exception TypeCondition
MailBeeExceptionAn error occurred and ThrowExceptions is true.

Example

This sample connects to a POP3 server and attempts to log in a user account using SASL NTLM method in Windows Integrated Authentication mode (passing credentials of the currently logged Windows user) even if NTLM is not listed in the server capabilities (the server may still support NTLM while not advertizing this). Use of other authentication methods is not allowed by this sample (they do not support obtaining the current Windows user's credentials and thus will raise exception is empty credentials are supplied by the caller).

[C#]
// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.Pop3Mail;

// The actual code (put it into a method of your class).
Pop3 pop = new Pop3();
pop.Connect("mail.domain.com");
pop.Login(null, null, AuthenticationMethods.SaslNtlm, 
    AuthenticationOptions.TryUnsupportedMethods, null);
pop.Disconnect();
[Visual Basic]
' To use the code below, import MailBee namespaces at the top of your code.
Imports MailBee
Imports MailBee.Pop3Mail

' The actual code (put it into a method of your class).
Dim pop As New Pop3
pop.Connect("mail.domain.com")
pop.Login(Nothing, Nothing, AuthenticationMethods.SaslNtlm, _
    AuthenticationOptions.TryUnsupportedMethods, Nothing)
pop.Disconnect()

See Also

Pop3 Class | MailBee.Pop3Mail Namespace | Pop3.Login Overload List | SaslMethod