Click or drag to resize
MimeKit

SmtpClientAuthenticateAsync Method (Encoding, ICredentials, CancellationToken)

Asynchronously authenticate using the supplied credentials.

Namespace:  MailKit.Net.Smtp
Assembly:  MailKit (in MailKit.dll) Version: 2.3.0
Syntax
C#
public override Task AuthenticateAsync(
	Encoding encoding,
	ICredentials credentials,
	CancellationToken cancellationToken = null
)

Parameters

encoding
Type: System.TextEncoding
The text encoding to use for the user's credentials.
credentials
Type: System.NetICredentials
The user's credentials.
cancellationToken (Optional)
Type: System.ThreadingCancellationToken
The cancellation token.

Return Value

Type: Task
An asynchronous task context.

Implements

IMailServiceAuthenticateAsync(Encoding, ICredentials, CancellationToken)
Exceptions
ExceptionCondition
ArgumentNullException

encoding is null.

-or-

credentials is null.

ServiceNotConnectedException The SmtpClient is not connected.
InvalidOperationException The SmtpClient is already authenticated.
NotSupportedException The SMTP server does not support authentication.
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.
SmtpCommandException The SMTP command failed.
SmtpProtocolException An SMTP protocol error occurred.
Remarks

If the SMTP server supports authentication, 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, on the other hand, authentication is not supported by the SMTP server, then this method will throw NotSupportedException. The Capabilities property can be checked for the Authentication flag to make sure the SMTP server supports authentication before calling this method.

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