コード例 #1
0
        /// <summary>
        /// Creates and starts an instance of SimpleSmtpServer that will listen on a specific port.
        /// </summary>
        /// <param name="port">port number the server should listen to</param>
        /// <param name="background">Whether listener thread blocks process from shutdown</param>
        /// <returns>The <see cref="SimpleSmtpServer">SmtpServer</see> waiting for message</returns>
        public static SimpleSmtpServer Start(int port, bool background = false)
        {
            SimpleSmtpServer server = new SimpleSmtpServer(port);

            Thread smtpServerThread = new Thread(server.Run);

            smtpServerThread.IsBackground = background;
            smtpServerThread.Start();

            // Block until the server socket is created
            try
            {
                server.StartedEvent.WaitOne();
            }
            catch
            {
                // Ignore don't care.
            }

            // If an exception occured during server startup, send it back.
            if (server.MainThreadException != null)
            {
                throw server.MainThreadException;
            }

            return(server);
        }
コード例 #2
0
ファイル: SmtpSetup.cs プロジェクト: TheSpider/nDumbster
 public static void Setup(TestContext testContext)
 {
     SmtpServer = SimpleSmtpServer.Start(25);
 }
コード例 #3
0
		/// <summary>
		/// Creates and starts an instance of SimpleSmtpServer that will listen on a specific port.
		/// </summary>
		/// <param name="port">port number the server should listen to</param>
        /// <param name="background">Whether listener thread blocks process from shutdown</param>
		/// <returns>The <see cref="SimpleSmtpServer">SmtpServer</see> waiting for message</returns>
		public static SimpleSmtpServer Start(int port,bool background = false)
		{
			SimpleSmtpServer server = new SimpleSmtpServer(port);

			Thread smtpServerThread = new Thread(server.Run);
            smtpServerThread.IsBackground = background;
			smtpServerThread.Start();
            
			// Block until the server socket is created
			try 
			{
				server.StartedEvent.WaitOne();
			} 
			catch 
			{
				// Ignore don't care.
			}

			// If an exception occured during server startup, send it back.
			if (server.MainThreadException != null)
            {
                throw server.MainThreadException;
			}

			return server;
		}
コード例 #4
0
		protected void SetUp() 
		{
			server = SimpleSmtpServer.Start(TEST_ALT_PORT);
			server2 = null;
		}
コード例 #5
0
		public SimpleSmtpServerTests()
		{
			server = null;
			server2 = null;
		}
コード例 #6
0
 public void Setup()
 {
     // NB Use port configured in App.config
     var client = new SmtpClient();
     smtpServer = SimpleSmtpServer.Start(client.Port);
 }