/// <summary> /// Initializes a new instance of the <see cref="SimpleSmtpServer"/> class. /// </summary> /// <param name="port">The port.</param> private SimpleSmtpServer(int port) { Port = port; _clientConnected = new AutoResetEvent(false); _serverReady = new AutoResetEvent(false); _processor = new SmtpProcessor(string.Empty, _receivedMail); }
/// <summary> /// Async Socket handler. /// </summary> /// <param name="result">The result.</param> private void SocketHandler(Socket socket) { if (this.cancellation.IsCancellationRequested) { return; } this.log.Debug("Entering Socket Handler."); try { using (socket) { this.log.Debug("Socket accepted and ready to be processed."); SmtpProcessor processor = new SmtpProcessor(string.Empty, this.Configuration.UseMessageStore ? this.smtpMessageStore : null); processor.MessageReceived += (sender, args) => { if (MessageReceived != null) { MessageReceived(this, args); } }; processor.ProcessConnection(socket); } } catch (ObjectDisposedException ex) { this.log.Warn("Object Disposed Exception. THIS IS EXPECTED ONLY IF SERVER WAS STOPPED.", ex); } catch (SocketException ex) { this.log.Warn("Socket Exception", ex); } }
/// <summary> /// Async Socket handler. /// </summary> /// <param name="result">The result.</param> private void _SocketHandler(IAsyncResult result) { if (this.stop) { return; } this.log.Debug("Entering Socket Handler."); if (this.Configuration.ProcessingDelayInMilliseconds > 0) { Thread.Sleep(this.Configuration.ProcessingDelayInMilliseconds); } try { TcpListener listener = (TcpListener)result.AsyncState; listener.BeginAcceptSocket(new AsyncCallback(this._SocketHandler), listener); this.log.Debug("Calling EndAcceptSocket."); using (Socket socket = listener.EndAcceptSocket(result)) { this.log.Debug("Socket accepted and ready to be processed."); SmtpProcessor processor = new SmtpProcessor(string.Empty, this.Configuration.UseMessageStore ? this.smtpMessageStore : null); processor.MessageReceived += (sender, args) => { if (MessageReceived != null) { MessageReceived(this, args); } }; processor.ProcessConnection(socket); } } catch (ObjectDisposedException ex) { this.log.Warn("Object Disposed Exception. THIS IS EXPECTED ONLY IF SERVER WAS STOPPED.", ex); } catch (SocketException ex) { this.log.Warn("Socket Exception", ex); } }
/// <summary> /// Async Socket handler. /// </summary> /// <param name="result">The result.</param> private void _SocketHandler(IAsyncResult result) { if (this.stop) { return; } this.log.Debug("Entering Socket Handler."); try { TcpListener listener = (TcpListener)result.AsyncState; listener.BeginAcceptSocket(new AsyncCallback(this._SocketHandler), listener); this.log.Debug("Calling EndAcceptSocket."); using (Socket socket = listener.EndAcceptSocket(result)) { this.log.Debug("Socket accepted and ready to be processed."); SmtpProcessor processor = new SmtpProcessor(string.Empty, this.Configuration.UseMessageStore ? this.smtpMessageStore : null); processor.MessageReceived += (sender, args) => { if (MessageReceived != null) { MessageReceived(this, args); } }; processor.ProcessConnection(socket); } } catch (ObjectDisposedException ex) { this.log.Warn("Object Disposed Exception. THIS IS EXPECTED ONLY IF SERVER WAS STOPPED.", ex); } catch (SocketException ex) { this.log.Warn("Socket Exception", ex); } }
/// <summary> /// Async Socket handler. /// </summary> /// <param name="result">The result.</param> private void _SocketHandler(IAsyncResult result) { if (this.stop) { return; } log.Debug("Entering Socket Handler."); try { TcpListener listener = (TcpListener)result.AsyncState; listener.BeginAcceptSocket(new AsyncCallback(_SocketHandler), listener); log.Debug("Calling EndAcceptSocket."); using (Socket socket = listener.EndAcceptSocket(result)) { log.Debug("Socket accepted and ready to be processed."); SmtpProcessor processor = new SmtpProcessor(string.Empty, smtpMessageStore); processor.ProcessConnection(socket); } } catch (ObjectDisposedException ex) { log.Warn("Object Disposed Exception. THIS IS EXPECTED ONLY IF SERVER WAS STOPPED.", ex); } catch (SocketException ex) { log.Warn("Socket Exception", ex); } }