Click or drag to resize
MimeKit

IMailServiceAuthenticateAsync Method (Encoding, String, String, CancellationToken)

Asynchronously authenticate using the specified user name and password.

Namespace:  MailKit
Assembly:  MailKit (in MailKit.dll) Version: 2.3.0
Syntax
C#
Task AuthenticateAsync(
	Encoding encoding,
	string userName,
	string password,
	CancellationToken cancellationToken = null
)

Parameters

encoding
Type: System.TextEncoding
The encoding to use for the user's credentials.
userName
Type: SystemString
The user name.
password
Type: SystemString
The password.
cancellationToken (Optional)
Type: System.ThreadingCancellationToken
The cancellation token.

Return Value

Type: Task
An asynchronous task context.
Exceptions
ExceptionCondition
ArgumentNullException

encoding is null.

-or-

userName is null.

-or-

password is null.

ObjectDisposedException The MailService has been disposed.
InvalidOperationException The MailService is not connected or is already authenticated.
OperationCanceledException The operation was canceled via the cancellation token.
AuthenticationException Authentication using the supplied credentials has failed.
SaslException A SASL authentication error occurred.
IOException An I/O error occurred.
ProtocolException A protocol error occurred.
Remarks

If the server supports one or more SASL authentication mechanisms, then the SASL mechanisms that both the client and server support are tried in order of greatest security to weakest security. Once a SASL authentication mechanism is found that both client and server support, the credentials are used to authenticate.

If the server does not support SASL or if no common SASL mechanisms can be found, then the default login command is used as a fallback.

Tip Tip
To prevent the usage of certain authentication mechanisms, simply remove them from the AuthenticationMechanisms hash set before calling this method.
See Also