ImapLogin Method (String, String, AuthenticationMethods, AuthenticationOptions, SaslMethod)
Logs in a mail account on the IMAP4 server.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
public bool Login(
	string accountName,
	string password,
	AuthenticationMethods authMethods,
	AuthenticationOptions authOptions,
	SaslMethod authUserDefined
)

Parameters

accountName
Type: SystemString
The user account name on the server.
password
Type: SystemString
The password of the user account on the server.
authMethods
Type: MailBeeAuthenticationMethods
A set of authentication methods which can be used when logging in a mailbox.
authOptions
Type: MailBeeAuthenticationOptions
Specifies the options which affect login process.
authUserDefined
Type: MailBeeSaslMethod
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

Type: Boolean
true if a login attempt succeeded; otherwise, false.
Exceptions
ExceptionCondition
MailBeeExceptionAn error occurred and ThrowExceptions is true.
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 "LOGIN account password" authentication in the worst case) if better methods are not available. However, if the IMAP4 server prohibits using LOGIN command (LOGINDISABLED extension is enabled), regular authentication option won't be available.

To use OAuth 2.0 authentication (XOAUTH2 in Gmail and Office 365), see explanations and the example in OAuth2 topic.

Examples
This sample connects to an IMAP4 server and attempts to log in a user account using SASL NTLM method in Integrated Windows 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 advertising 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).
// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.ImapMail;

// The actual code (put it into a method of your class).
Imap imp = new Imap();
imp.Connect("mail.domain.com");
imp.Login(null, null, AuthenticationMethods.SaslNtlm, AuthenticationOptions.TryUnsupportedMethods, null);
imp.Disconnect();
See Also