System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.AuthenticateContinue C# (CSharp) Method

AuthenticateContinue() private method

private AuthenticateContinue ( ) : bool
return bool
            private bool AuthenticateContinue()
            {
                for (;;)
                {
                    // We don't need credential on the continued auth assuming they were captured on the first call.
                    // That should always work, otherwise what if a new credential has been returned?
                    Authorization auth = _connection._authenticationModules[_currentModule].Authenticate(_authResponse, null, _connection, _connection._client.TargetName, _connection._channelBindingToken);
                    if (auth == null)
                    {
                        throw new SmtpException(SR.Format(SR.SmtpAuthenticationFailed));
                    }

                    IAsyncResult result = AuthCommand.BeginSend(_connection, auth.Message, s_authenticateContinueCallback, this);
                    if (!result.CompletedSynchronously)
                    {
                        return false;
                    }

                    LineInfo info = AuthCommand.EndSend(result);
                    if ((int)info.StatusCode == 235)
                    {
                        _connection._authenticationModules[_currentModule].CloseContext(_connection);
                        _connection._isConnected = true;
                        InvokeCallback();
                        return false;
                    }
                    else if ((int)info.StatusCode != 334)
                    {
                        return true;
                    }
                    _authResponse = info.Line;
                }
            }

Usage Example

 private static void AuthenticateContinueCallback(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         SmtpConnection.ConnectAndHandshakeAsyncResult asyncState = (SmtpConnection.ConnectAndHandshakeAsyncResult)result.AsyncState;
         try
         {
             LineInfo info = AuthCommand.EndSend(result);
             if (info.StatusCode == ((SmtpStatusCode)0xeb))
             {
                 asyncState.connection.authenticationModules[asyncState.currentModule].CloseContext(asyncState.connection);
                 asyncState.connection.isConnected = true;
                 asyncState.InvokeCallback();
             }
             else
             {
                 if (info.StatusCode == ((SmtpStatusCode)0x14e))
                 {
                     asyncState.authResponse = info.Line;
                     if (!asyncState.AuthenticateContinue())
                     {
                         return;
                     }
                 }
                 asyncState.Authenticate();
             }
         }
         catch (Exception exception)
         {
             asyncState.InvokeCallback(exception);
         }
     }
 }