System.Net.Mail.SmtpConnection.AuthSupported C# (CSharp) Method

AuthSupported() private method

private AuthSupported ( ISmtpAuthenticationModule module ) : bool
module ISmtpAuthenticationModule
return bool
        internal bool AuthSupported(ISmtpAuthenticationModule module)
        {
            if (module is SmtpLoginAuthenticationModule)
            {
                if ((_supportedAuth & SupportedAuth.Login) > 0)
                {
                    return true;
                }
            }
            else if (module is SmtpNegotiateAuthenticationModule)
            {
                if ((_supportedAuth & SupportedAuth.GSSAPI) > 0)
                {
                    _sawNegotiate = true;
                    return true;
                }
            }
            else if (module is SmtpNtlmAuthenticationModule)
            {
                // Don't try ntlm if negotiate has been tried
                if ((!_sawNegotiate && (_supportedAuth & SupportedAuth.NTLM) > 0))
                {
                    return true;
                }
            }

            return false;
        }
    }

Usage Example

Example #1
0
            void Authenticate() //8
            {
                //if no credentials were supplied, try anonymous
                //servers don't appear to anounce that they support anonymous login.
                if (connection.credentials != null)
                {
                    while (++currentModule < connection.authenticationModules.Length)
                    {
                        //only authenticate if the auth protocol is supported
                        ISmtpAuthenticationModule module = connection.authenticationModules[currentModule];
                        if (!connection.AuthSupported(module))
                        {
                            continue;
                        }

                        NetworkCredential credential = connection.credentials.GetCredential(host, port, module.AuthenticationType);
                        if (credential == null)
                        {
                            continue;
                        }
                        Authorization auth = connection.SetContextAndTryAuthenticate(module, credential, m_OuterResult);

                        if (auth != null && auth.Message != null)
                        {
                            IAsyncResult result = AuthCommand.BeginSend(connection, connection.authenticationModules[currentModule].AuthenticationType, auth.Message, authenticateCallback, this);
                            if (!result.CompletedSynchronously)
                            {
                                return;
                            }

                            LineInfo info = AuthCommand.EndSend(result);

                            if ((int)info.StatusCode == 334)
                            {
                                authResponse = info.Line;
                                if (!AuthenticateContinue())
                                {
                                    return;
                                }
                            }
                            else if ((int)info.StatusCode == 235)
                            {
                                module.CloseContext(connection);
                                connection.isConnected = true;
                                break;
                            }
                        }
                    }

                    //try anonymous if didn't authenticate
                    //if (!connection.isConnected) {
                    //    throw new SmtpException(SR.GetString(SR.SmtpAuthenticationFailed));
                    // }
                }

                connection.isConnected = true;
                InvokeCallback();
            }
All Usage Examples Of System.Net.Mail.SmtpConnection::AuthSupported