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

SendEHello() private method

private SendEHello ( ) : bool
return bool
            private bool SendEHello()
            {
                IAsyncResult result = EHelloCommand.BeginSend(_connection, _connection._client.clientDomain, s_sendEHelloCallback, this);
                if (result.CompletedSynchronously)
                {
                    _connection._extensions = EHelloCommand.EndSend(result);
                    _connection.ParseExtensions(_connection._extensions);
                    // If we already have a TlsStream, this is the second EHLO cmd
                    // that we sent after TLS handshake compelted. So skip TLS and
                    // continue with Authenticate.
                    if (_connection._networkStream is TlsStream)
                    {
                        Authenticate();
                        return true;
                    }

                    if (_connection.EnableSsl)
                    {
                        if (!_connection._serverSupportsStartTls)
                        {
                            // Either TLS is already established or server does not support TLS
                            if (!(_connection._networkStream is TlsStream))
                            {
                                throw new SmtpException(SR.Format(SR.MailServerDoesNotSupportStartTls));
                            }
                        }

                        SendStartTls();
                    }
                    else
                    {
                        Authenticate();
                    }
                    return true;
                }
                return false;
            }

Usage Example

 private static void HandshakeCallback(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         SmtpConnection.ConnectAndHandshakeAsyncResult asyncState = (SmtpConnection.ConnectAndHandshakeAsyncResult)result.AsyncState;
         try
         {
             try
             {
                 LineInfo info = asyncState.connection.Reader.CurrentReader.EndReadLine(result);
                 if (info.StatusCode != SmtpStatusCode.ServiceReady)
                 {
                     asyncState.InvokeCallback(new SmtpException(info.StatusCode, info.Line, true));
                 }
                 else if (!asyncState.SendEHello())
                 {
                 }
             }
             catch (SmtpException)
             {
                 if (!asyncState.SendHello())
                 {
                 }
             }
         }
         catch (Exception exception)
         {
             asyncState.InvokeCallback(exception);
         }
     }
 }
All Usage Examples Of System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult::SendEHello