public override Task AuthenticateAsync( Encoding encoding, ICredentials credentials, CancellationToken cancellationToken = default )
encoding is null.
credentials is null.
|The SmtpClient is not connected.
|The SmtpClient is already authenticated.
|The SMTP server does not support authentication.
|The operation was canceled via the cancellation token.
|Authentication using the supplied credentials has failed.
|A SASL authentication error occurred.
|An I/O error occurred.
|The SMTP command failed.
|An SMTP protocol error occurred.
Asynchronously authenticates using the supplied credentials.
If the SMTP server supports authentication, then the SASL mechanisms that both the client and server support (not including any OAUTH mechanisms) 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.
|To prevent the usage of certain authentication mechanisms, simply remove them from the AuthenticationMechanisms hash set before calling this method.