private bool SendEHello()
            {
                IAsyncResult result = EHelloCommand.BeginSend(this.connection, this.connection.client.clientDomain, sendEHelloCallback, this);

                if (!result.CompletedSynchronously)
                {
                    return(false);
                }
                this.connection.extensions = EHelloCommand.EndSend(result);
                this.connection.ParseExtensions(this.connection.extensions);
                if (this.connection.pooledStream.NetworkStream is TlsStream)
                {
                    this.Authenticate();
                    return(true);
                }
                if (this.connection.EnableSsl)
                {
                    if (!this.connection.serverSupportsStartTls && !(this.connection.pooledStream.NetworkStream is TlsStream))
                    {
                        throw new SmtpException(SR.GetString("MailServerDoesNotSupportStartTls"));
                    }
                    this.SendStartTls();
                }
                else
                {
                    this.Authenticate();
                }
                return(true);
            }
 private static void SendEHelloCallback(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         SmtpConnection.ConnectAndHandshakeAsyncResult asyncState = (SmtpConnection.ConnectAndHandshakeAsyncResult)result.AsyncState;
         try
         {
             try
             {
                 asyncState.connection.extensions = EHelloCommand.EndSend(result);
                 asyncState.connection.ParseExtensions(asyncState.connection.extensions);
                 if (asyncState.connection.pooledStream.NetworkStream is TlsStream)
                 {
                     asyncState.Authenticate();
                     return;
                 }
             }
             catch (SmtpException exception)
             {
                 if ((exception.StatusCode != SmtpStatusCode.CommandUnrecognized) && (exception.StatusCode != SmtpStatusCode.CommandNotImplemented))
                 {
                     throw exception;
                 }
                 if (!asyncState.SendHello())
                 {
                     return;
                 }
             }
             if (asyncState.connection.EnableSsl)
             {
                 if (!asyncState.connection.serverSupportsStartTls && !(asyncState.connection.pooledStream.NetworkStream is TlsStream))
                 {
                     throw new SmtpException(SR.GetString("MailServerDoesNotSupportStartTls"));
                 }
                 asyncState.SendStartTls();
             }
             else
             {
                 asyncState.Authenticate();
             }
         }
         catch (Exception exception2)
         {
             asyncState.InvokeCallback(exception2);
         }
     }
 }
Esempio n. 3
0
            bool SendEHello()//4
            {
                IAsyncResult result = EHelloCommand.BeginSend(connection, connection.client.clientDomain, 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.pooledStream.NetworkStream is TlsStream)
                    {
                        Authenticate();
                        return(true);
                    }

                    if (connection.EnableSsl)
                    {
#if !FEATURE_PAL
                        if (!connection.serverSupportsStartTls)
                        {
                            // Either TLS is already established or server does not support TLS
                            if (!(connection.pooledStream.NetworkStream is TlsStream))
                            {
                                throw new SmtpException(SR.GetString(SR.MailServerDoesNotSupportStartTls));
                            }
                        }

                        SendStartTls();
#else // FEATURE_PAL
                        throw new NotSupportedException("ROTORTODO");
#endif // !FEATURE_PAL
                    }
                    else
                    {
                        Authenticate();
                    }
                    return(true);
                }
                return(false);
            }
Esempio n. 4
0
            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);
            }
Esempio n. 5
0
            private static void SendEHelloCallback(IAsyncResult result)
            {
                if (!result.CompletedSynchronously)
                {
                    ConnectAndHandshakeAsyncResult thisPtr = (ConnectAndHandshakeAsyncResult)result.AsyncState;
                    try
                    {
                        try
                        {
                            thisPtr._connection._extensions = EHelloCommand.EndSend(result);
                            thisPtr._connection.ParseExtensions(thisPtr._connection._extensions);

                            // If we already have a SSlStream, this is the second EHLO cmd
                            // that we sent after TLS handshake compelted. So skip TLS and
                            // continue with Authenticate.
                            if (thisPtr._connection._networkStream is TlsStream)
                            {
                                thisPtr.Authenticate();
                                return;
                            }
                        }

                        catch (SmtpException e)
                        {
                            if ((e.StatusCode != SmtpStatusCode.CommandUnrecognized) &&
                                (e.StatusCode != SmtpStatusCode.CommandNotImplemented))
                            {
                                throw;
                            }

                            if (!thisPtr.SendHello())
                            {
                                return;
                            }
                        }


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

                            thisPtr.SendStartTls();
                        }
                        else
                        {
                            thisPtr.Authenticate();
                        }
                    }
                    catch (Exception e)
                    {
                        thisPtr.InvokeCallback(e);
                    }
                }
            }