MailBee.NET Objects 7.2

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

Logs in a mail account on the IMAP4 server.

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

Parameters

targetName
The Service Principal Name (SPN) of the IMAP4 server. Only used with GSSAPI authentication method. If an empty string, NTLM method will be used for GSSAPI. If a null reference (Nothing in Visual Basic), MailBee will autodetect SPN as "IMAP/serverName" and use Kerberos for GSSAPI. If set to a non-empty string, MailBee will also select Kerberos for GSSAPI and use this value as SPN.
domain
The user account domain on the server. Only used with NTLM and GSSAPI authentication methods. You can leave it a null reference to use the current domain.
accountName
The user account name on the server (can be empty for NTLM and GSSAPI).
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

Use this overload if you need to authenticate with NTLM and GSSAPI (usually, against MS Exchange or MS IIS) and need to explicitly specify user domain or custom SPN. For other cases, you can use simpler overloads.

Exceptions

Exception Type Condition
MailBeeException An error occurred and ThrowExceptions is true.

Example

This sample connects to an IMAP4 server and attempts to log in a user account using SASL GSSAPI method in Integrated Windows Authentication mode and NTLM is selected as the underlying implementation because targetName is an empty string.

[C#]
// 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, null, AuthenticationMethods.SaslGssApi, AuthenticationOptions.TryUnsupportedMethods, null);
imp.Disconnect();
[Visual Basic]
' To use the code below, import MailBee namespaces at the top of your code.
Imports MailBee
Imports MailBee.ImapMail

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

See Also

Imap Class | MailBee.ImapMail Namespace | Imap.Login Overload List | SaslMethod