public override async Task ExecuteAsync(SmtpSession smtpSession, CancellationToken token) { string[] parts = Arguments.Split(new [] { ' ' }, 2); if (parts == null || parts.Length == 0 || parts.Length > 2) { await smtpSession.SendReplyAsync(ReplyCode.InvalidArguments, "Expected mechanism and optional initial response", token); return; } string mechanismName = parts[0]; IAuthenticationMechanism mechanism = smtpSession.ImplementationFactory.Authentication.Get(mechanismName); if (mechanism == null) { await smtpSession.SendReplyAsync(ReplyCode.InvalidArguments, "Unknown mechanism", token); return; } var authSession = mechanism.CreateSession(smtpSession); UserData userData; try { userData = await authSession.AuthenticateAsync(smtpSession.UserStore, token, false); } catch (ArgumentException) { await smtpSession.SendReplyAsync(ReplyCode.InvalidArguments, "Invalid arguments", token); return; } smtpSession.AuthenticatedUser = userData; await smtpSession.SendReplyAsync(ReplyCode.AuthenticationComplete, "Authentication unsuccessful", token); }