示例#1
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);
            }
        }
        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);
            }
        }
示例#3
0
        public bool Initialize(IHost hostApplication)
        {
            My = hostApplication;

            if (!System.IO.File.Exists("SMTP.cfg"))
            {
                SMTPConfig.Add("SMTPPort", "25");
                SMTPConfig.Add("RootMailDir", "./mail/");
                FeuerwehrCloud.Helper.AppSettings.Save(SMTPConfig, "SMTP.cfg");
            }
            SMTPConfig = FeuerwehrCloud.Helper.AppSettings.Load("SMTP.cfg");
            //System.Environment.MachineName +



            smtpServer = new SmtpServer
            {
                Configuration =
                {
                    DefaultGreeting = System.Environment.MachineName + ".feuerwehrcloud.de FeuerwehrCloud DEIVA BOSMTP MAIL service ready at"
                }
            };
            smtpServer.DefaultResponderFactory =
                new SmtpResponderFactory(smtpServer.Configuration)
            {
                DataResponder = new BOSSMTPDataResponder(smtpServer.Configuration, SMTPConfig["RootMailDir"], this)
            };
            FeuerwehrCloud.Helper.Logger.WriteLine("|  *** SMTPServer loaded: listening on port: " + SMTPConfig["SMTPPort"]);
            smtpServer.BindAndListenTo(IPAddress.Any, int.Parse(SMTPConfig["SMTPPort"]));
            return(true);
        }
示例#4
0
        private static SmtpServer StartSmtpServer()
        {
            var smtpServer = new SmtpServer
            {
                Configuration =
                {
                    DefaultGreeting = "Goman.MailServer"
                }
            };

            smtpServer.DefaultResponderFactory =
                new SmtpResponderFactory(smtpServer.Configuration)
            {
                DataResponder = new ExampleDataResponder(smtpServer.Configuration, RootMailDir)
            };

            smtpServer.BindAndListenTo(IPAddress.Any, 25);
            return(smtpServer);
        }
示例#5
0
        private static SmtpServer StartSmtpServer()
        {
            var smtpServer = new SmtpServer
            {
                Configuration =
                {
                    DefaultGreeting = "Simple.MailServer Example"
                }
            };

            smtpServer.DefaultResponderFactory =
                new DefaultSmtpResponderFactory <ISmtpServerConfiguration>(smtpServer.Configuration)
            {
                DataResponder = new ExampleDataResponder(smtpServer.Configuration, RootMailDir)
                                // ... inject other responders here as needed (or leave default)
            };

            smtpServer.BindAndListenTo(IPAddress.Loopback, 25);
            return(smtpServer);
        }