コード例 #1
0
ファイル: SmtpServer.cs プロジェクト: nemec/simple.mailserver
        public static SmtpServer CreateAndBind(IPAddress serverListenAddress, int port)
        {
            var smtpServer = new SmtpServer();

            smtpServer.BindAndListenTo(serverListenAddress, port);
            return(smtpServer);
        }
コード例 #2
0
        public SmtpConnection(SmtpServer server, PortListener portBinding, TcpClient tcpClient)
            : base(portBinding, tcpClient)
        {
            if (server == null) throw new ArgumentNullException("server");

            Server = server;
        }
コード例 #3
0
        public static SmtpServer CreateAndBind(IPAddress serverListenAddress, int port)
        {
            var smtpServer = new SmtpServer();
            smtpServer.BindAndListenTo(serverListenAddress, port);

            return smtpServer;
        }
コード例 #4
0
        public void SmtpServer_should_be_able_to_receive_mail_from_SmtpClient()
        {
            var mockEmailValidator = new Mock<IEmailValidator>();
            mockEmailValidator.Setup(x => x.Validate(It.IsAny<string>())).Returns(true);

            var testPort = TestHelpers.GetTestPort();
            var mailDataCollector = new TestMailDataCollector();

            using (var smtpServer = new SmtpServer())
            {
                var responderFactory = new SmtpResponderFactory(smtpServer.Configuration, mockEmailValidator.Object) { DataResponder = mailDataCollector };
                smtpServer.DefaultResponderFactory = responderFactory;
                smtpServer.BindAndListenTo(IPAddress.Loopback, testPort);

                var sendMailTask =
                    Task.Factory.StartNew(() => SendMail(testPort, "*****@*****.**", "*****@*****.**", "subject", "body"),
                        TaskCreationOptions.LongRunning);

                Assert.True(sendMailTask.Wait(3000));
                mockEmailValidator.Verify(x => x.Validate("*****@*****.**"));
                mockEmailValidator.Verify(x => x.Validate("*****@*****.**"));

                var mailData = mailDataCollector.MailData;
                Assert.Contains("*****@*****.**", mailData);
                Assert.Contains("*****@*****.**", mailData);
                Assert.Contains("subject", mailData);
                Assert.Contains("body", mailData);
            }
        }
コード例 #5
0
        public SmtpConnection(SmtpServer server, PortListener portBinding, TcpClient tcpClient)
            : base(portBinding, tcpClient)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            Server = server;
        }
コード例 #6
0
        private static SmtpServer StartSmtpServer()
        {
            var smtpServer = new SmtpServer
            {
                Configuration =
                {
                    DefaultGreeting = "Simple.MailServer Example"
                }
            };
            smtpServer.DefaultResponderFactory = 
                new SmtpResponderFactory(smtpServer.Configuration)
            {
                DataResponder = new ExampleDataResponder(smtpServer.Configuration, RootMailDir)
                // ... inject other responders here as needed (or leave default)
            };

            smtpServer.BindAndListenTo(IPAddress.Loopback, 25);
            return smtpServer;
        }
コード例 #7
0
        public void SmtpServer_should_be_able_to_receive_mail_from_SmtpClient()
        {
            var testPort = GetTestPort();
            var mailDataCollector = new TestMailDataCollector();

            using (var smtpServer = new SmtpServer())
            {
                var responderFactory = new DefaultSmtpResponderFactory<ISmtpServerConfiguration>(smtpServer.Configuration) { DataResponder = mailDataCollector };
                smtpServer.DefaultResponderFactory = responderFactory;
                smtpServer.BindAndListenTo(IPAddress.Loopback, testPort);

                var sendMailTask =
                    Task.Factory.StartNew(() => SendMail(testPort, "*****@*****.**", "*****@*****.**", "subject", "body"),
                        TaskCreationOptions.LongRunning);

                Assert.True(sendMailTask.Wait(1500));

                var mailData = mailDataCollector.MailData;
                Assert.Contains("*****@*****.**", mailData);
                Assert.Contains("*****@*****.**", mailData);
                Assert.Contains("subject", mailData);
                Assert.Contains("body", mailData);
            }
        }