Пример #1
0
 void session_Sent(SmtpSession sender, string line)
 {
     if (Sent != null)
     {
         Sent(sender, line);
     }
 }
Пример #2
0
 void session_Error(SmtpSession sender, Exception ex)
 {
     if (Error != null)
     {
         Error(this, ex);
     }
 }
Пример #3
0
 void session_End(SmtpSession sender)
 {
     if (End != null)
     {
         End(sender);
     }
 }
Пример #4
0
 void session_Received(SmtpSession sender, string line)
 {
     if (Received != null)
     {
         Received(sender, line);
     }
 }
Пример #5
0
        /// <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();
            }
        }
Пример #6
0
 void session_Error(SmtpSession sender, Exception ex)
 {
     if (Error != null) Error(this, ex);
 }
Пример #7
0
 void session_Received(SmtpSession sender, string line)
 {
     if (Received != null) Received(sender, line);
 }
Пример #8
0
 void session_Sent(SmtpSession sender, string line)
 {
     if (Sent != null) Sent(sender, line);
 }
Пример #9
0
 void session_End(SmtpSession sender)
 {
     if (End != null) End(sender);
 }
Пример #10
0
        /// <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();
            }
        }
Пример #11
0
 static void mock_Sent(SmtpSession sender, string line)
 {
     Console.WriteLine("{0}> {1}", sender.Id, line);
 }
Пример #12
0
 static void mock_Received(SmtpSession sender, string line)
 {
     Console.WriteLine("{0}< {1}", sender.Id, line);
 }
Пример #13
0
 static void mock_End(SmtpSession sender)
 {
     Console.WriteLine("{0}= Session Ended", sender.Id);
 }