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); } } }
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); } } }