/// <summary> /// Execute the command. /// </summary> /// <param name="context">The execution context to operate on.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A task which asynchronously performs the execution.</returns> public override async Task ExecuteAsync(ISmtpSessionContext context, CancellationToken cancellationToken) { switch (Method) { case AuthenticationMethod.Plain: if (await TryPlainAsync(context, cancellationToken) == false) { await context.Text.ReplyAsync(SmtpResponse.AuthenticationFailed, cancellationToken).ConfigureAwait(false); return; } break; case AuthenticationMethod.Login: if (await TryLoginAsync(context, cancellationToken) == false) { await context.Text.ReplyAsync(SmtpResponse.AuthenticationFailed, cancellationToken).ConfigureAwait(false); return; } break; } if (await _userAuthenticator.AuthenticateAsync(_user, _password).ConfigureAwait(false) == false) { await context.Text.ReplyAsync(SmtpResponse.AuthenticationFailed, cancellationToken).ConfigureAwait(false); return; } await context.Text.ReplyAsync(SmtpResponse.AuthenticationSuccessful, cancellationToken).ConfigureAwait(false); context.StateMachine.RemoveCommand(SmtpState.WaitingForMail, "AUTH"); context.StateMachine.RemoveCommand(SmtpState.WaitingForMailSecure, "AUTH"); }