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 SendStartTlsCallback(IAsyncResult result) { if (!result.CompletedSynchronously) { SmtpConnection.ConnectAndHandshakeAsyncResult asyncState = (SmtpConnection.ConnectAndHandshakeAsyncResult)result.AsyncState; try { StartTlsCommand.EndSend(result); TlsStream stream = new TlsStream(asyncState.connection.pooledStream.ServicePoint.Host, asyncState.connection.pooledStream.NetworkStream, asyncState.connection.ClientCertificates, asyncState.connection.pooledStream.ServicePoint, asyncState.connection.client, asyncState.m_OuterResult.ContextCopy); asyncState.connection.pooledStream.NetworkStream = stream; asyncState.connection.responseReader = new SmtpReplyReaderFactory(asyncState.connection.pooledStream.NetworkStream); asyncState.SendEHello(); } catch (Exception exception) { asyncState.InvokeCallback(exception); } } }