Exemplo n.º 1
0
 private static void HandshakeCallback(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         ConnectAndHandshakeAsyncResult thisPtr = (ConnectAndHandshakeAsyncResult)result.AsyncState !;
         try
         {
             try
             {
                 LineInfo info = thisPtr._connection.Reader !.CurrentReader !.EndReadLine(result);
                 if (info.StatusCode != SmtpStatusCode.ServiceReady)
                 {
                     thisPtr.InvokeCallback(new SmtpException(info.StatusCode, info.Line, true));
                     return;
                 }
                 if (!thisPtr.SendEHello())
                 {
                     return;
                 }
             }
             catch (SmtpException)
             {
                 if (!thisPtr.SendHello())
                 {
                     return;
                 }
             }
         }
         catch (Exception e)
         {
             thisPtr.InvokeCallback(e);
         }
     }
 }
Exemplo n.º 2
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);
                    }
                }
            }