void session_Sent(SmtpSession sender, string line) { if (Sent != null) { Sent(sender, line); } }
void session_Error(SmtpSession sender, Exception ex) { if (Error != null) { Error(this, ex); } }
void session_End(SmtpSession sender) { if (End != null) { End(sender); } }
void session_Received(SmtpSession sender, string line) { if (Received != null) { Received(sender, line); } }
/// <summary> /// run server /// </summary> private void Run() { try { _smtpListener = new TcpListener(IPAddress.Any, 25); // open listener for port _smtpListener.Start(); if (Started != null) { Started(this, _smtpListener); } int count = 1; try { while (true) { Socket clientSocket = _smtpListener.AcceptSocket(); if (Connect != null) { Connect(this, clientSocket); } SmtpSession session = new SmtpSession(clientSocket, count); session.Error += new SmtpSession.ExceptionHandler(session_Error); session.Sent += new SmtpSession.DataHandler(session_Sent); session.Received += new SmtpSession.DataHandler(session_Received); session.End += new SmtpSession.EndHandler(session_End); Thread sessionThread = new Thread(new ThreadStart(session.Process)); sessionThread.Start(); count++; } } catch (InvalidOperationException) { // server stopped } finally { _smtpListener.Stop(); } } catch (Exception ex) { if (Error != null) { Error(this, ex); } _smtpListener.Stop(); } }
void session_Error(SmtpSession sender, Exception ex) { if (Error != null) Error(this, ex); }
void session_Received(SmtpSession sender, string line) { if (Received != null) Received(sender, line); }
void session_Sent(SmtpSession sender, string line) { if (Sent != null) Sent(sender, line); }
void session_End(SmtpSession sender) { if (End != null) End(sender); }
/// <summary> /// run server /// </summary> private void Run() { try { _smtpListener = new TcpListener(IPAddress.Any, 25); // open listener for port _smtpListener.Start(); if (Started != null) Started(this, _smtpListener); int count = 1; try { while (true) { Socket clientSocket = _smtpListener.AcceptSocket(); if (Connect != null) Connect(this, clientSocket); SmtpSession session = new SmtpSession(clientSocket, count); session.Error += new SmtpSession.ExceptionHandler(session_Error); session.Sent += new SmtpSession.DataHandler(session_Sent); session.Received += new SmtpSession.DataHandler(session_Received); session.End += new SmtpSession.EndHandler(session_End); Thread sessionThread = new Thread(new ThreadStart(session.Process)); sessionThread.Start(); count++; } } catch (InvalidOperationException) { // server stopped } finally { _smtpListener.Stop(); } } catch (Exception ex) { if (Error != null) { Error(this, ex); } _smtpListener.Stop(); } }
static void mock_Sent(SmtpSession sender, string line) { Console.WriteLine("{0}> {1}", sender.Id, line); }
static void mock_Received(SmtpSession sender, string line) { Console.WriteLine("{0}< {1}", sender.Id, line); }
static void mock_End(SmtpSession sender) { Console.WriteLine("{0}= Session Ended", sender.Id); }