Esempio n. 1
0
        public void TestSendExternalMailToMailboxContainingQuote()
        {
            var range = SingletonProvider <TestSetup> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer");

            range.RequireSMTPAuthExternalToExternal = false;
            range.Save();


            // Set up a server listening on port 250 which accepts email for [email protected]
            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["\"John Smith\"@dummy-example.com"] = 250;

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone);

                var smtpClientSimulator = new SmtpClientSimulator();
                smtpClientSimulator.Send("\"John Smith\"@example.com",
                                         "\"John Smith\"@dummy-example.com", "Mail 1", "Test message");


                // This should now be processed via the rule -> route -> external server we've set up.
                server.WaitForCompletion();

                Assert.IsTrue(server.MessageData.Contains("Test message"));
            }
        }
Esempio n. 2
0
        public void SmtpServerNOTSupportingStartTls_StartTlsRequired()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Set up a server listening on port 250 which accepts email for [email protected]
            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSNone))
            {
                server.SetCertificate(SslSetup.GetCertificate());
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSSTARTTLSRequired);

                var smtpClient = new SmtpClientSimulator();
                smtpClient.Send(account.Address, "*****@*****.**", "Test", "Test message");

                CustomAsserts.AssertRecipientsInDeliveryQueue(0);

                // This should now be processed via the rule -> route -> external server we've set up.
                server.WaitForCompletion();

                var msg = Pop3ClientSimulator.AssertGetFirstMessageText("*****@*****.**", "test");

                Assert.IsTrue(msg.Contains("Server does not support STARTTLS"));
            }
        }
Esempio n. 3
0
        public void ShouldBePossibleToSendToRouteWithTargetIPAddress()
        {
            // Set up a server listening on port 250 which accepts email for [email protected]
            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSNone);
                route.TargetSMTPHost = "127.0.0.1";
                route.Save();

                var smtpSimulator = new SmtpClientSimulator();
                smtpSimulator.Send("*****@*****.**",
                                   "*****@*****.**", "Mail 1", "Test message");


                // This should now be processed via the rule -> route -> external server we've set up.
                server.WaitForCompletion();
                var log = LogHandler.ReadCurrentDefaultLog();

                Assert.IsTrue(server.MessageData.Contains("Test message"));
            }
        }
        public void TestDeliverToServerNotSupportingEHLORequiredConnectionSecurity()
        {
            Assert.AreEqual(0, _status.UndeliveredMessages.Length);

            var deliveryResults = new Dictionary <string, int>()
            {
                { "*****@*****.**", 250 }
            };

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.ServerSupportsEhlo = false;
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                // Add a route so we can conenct to localhost.
                TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSSTARTTLSRequired);

                // Send message to this route.

                SmtpClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Test", "Test message");

                // Wait for the client to disconnect.
                server.WaitForCompletion();

                CustomAsserts.AssertRecipientsInDeliveryQueue(0, true);

                var msg = Pop3ClientSimulator.AssertGetFirstMessageText("*****@*****.**", "test");
                Assert.IsTrue(msg.Contains("Server does not support EHLO command."));
            }
        }
Esempio n. 5
0
        public void TestSenderAsLocalDomainSendToLocalAccountPass()
        {
            int   smtpServerPort = TestSetup.GetNextFreePort();
            Route route          = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false);

            route.TreatSenderAsLocalDomain = true;
            route.Save();

            SecurityRange range =
                SingletonProvider <TestSetup> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer");

            range.RequireSMTPAuthLocalToLocal = false;
            range.Save();

            Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var    smtpClientSimulator = new SmtpClientSimulator();
            string result;

            smtpClientSimulator.Send("*****@*****.**", account1.Address, "Mail 1", "Mail 1", out result);

            string text = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test");

            Assert.IsTrue(text.Contains("Mail 1"));
        }
Esempio n. 6
0
        public void TestDeliverToMyselfOnLocalPort()
        {
            Assert.AreEqual(0, _status.UndeliveredMessages.Length);

            // Add a route so we can conenct to localhost.
            TestSetup.AddRoutePointingAtLocalhost(1, 25, false);

            // Send message to this route.
            SmtpClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "subject", "body");

            for (int i = 0; i < 40; i++)
            {
                string s = _status.UndeliveredMessages;
                if (s.Contains("\t\[email protected]"))
                {
                    break;
                }

                Thread.Sleep(250);
            }

            // Wait for the bounce message to be delivered.
            CustomAsserts.AssertRecipientsInDeliveryQueue(0, true);

            string message = Pop3ClientSimulator.AssertGetFirstMessageText("*****@*****.**", "test");

            Assert.IsTrue(message.Contains("this would mean connecting to myself."));
        }
Esempio n. 7
0
        public void TreatRecipientAsExternalDomainPermitted()
        {
            int   smtpServerPort = TestSetup.GetNextFreePort();
            Route route          = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false);

            route.TreatRecipientAsLocalDomain = false;
            route.Save();

            SecurityRange range =
                SingletonProvider <TestSetup> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer");

            range.AllowDeliveryFromRemoteToRemote   = true;
            range.RequireSMTPAuthExternalToExternal = false;
            range.Save();

            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;

            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                var    smtpClientSimulator = new SmtpClientSimulator();
                string result;
                smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result);

                server.WaitForCompletion();

                server.MessageData.Contains("Mail 1");
            }
        }
Esempio n. 8
0
        public void TestDeliverySuccessSingleRecipientMissingQuitResponse()
        {
            Assert.AreEqual(0, _status.UndeliveredMessages.Length);

            // No valid recipients...
            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.AddRecipientResult(deliveryResults);
                server.StartListen();
                server.SimulatedError = SimulatedErrorType.DisconnectWithoutReplyOnQuit;

                // Add a route so we can connect to localhost.
                TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);

                // Send message to this route.
                var smtp       = new SmtpClientSimulator();
                var recipients = new List <string>();
                recipients.Add("*****@*****.**");
                smtp.Send("*****@*****.**", recipients, "Test", "DeliverySuccessNoQuitResponse");

                // Wait for the client to disconnect.
                server.WaitForCompletion();

                CustomAsserts.AssertRecipientsInDeliveryQueue(0, false);

                Assert.IsTrue(server.MessageData.Contains("DeliverySuccessNoQuitResponse"));
            }
        }
Esempio n. 9
0
        public void TreatRecipientAsLocalDomain()
        {
            int   smtpServerPort = TestSetup.GetNextFreePort();
            Route route          = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false);

            route.TreatRecipientAsLocalDomain = true;
            route.Save();

            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;

            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                var    smtpClientSimulator = new SmtpClientSimulator();
                string result;
                smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result);

                server.WaitForCompletion();

                server.MessageData.Contains("Mail 1");
            }
        }
        public void DoNotUseStartTlsIfNotEnabledButAvailable()
        {
            // No valid recipients...
            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSSTARTTLSOptional))
            {
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone);

                // Send message to this route.
                var smtp = new SmtpClientSimulator();
                smtp.Send("*****@*****.**", "*****@*****.**", "Test", "Test message");


                // Wait for the client to disconnect.
                server.WaitForCompletion();

                CustomAsserts.AssertRecipientsInDeliveryQueue(0, false);

                Assert.IsNotNullOrEmpty(server.MessageData);

                Assert.IsFalse(LogHandler.DefaultLogContains("220 Ready to start TLS"));
            }
        }
Esempio n. 11
0
        public void SmtpServerSupportingStartTls_StartTlsOptional()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Set up a server listening on port 250 which accepts email for [email protected]
            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSSTARTTLSRequired))
            {
                server.SetCertificate(SslSetup.GetCertificate());
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSSTARTTLSOptional);

                var smtpClient = new SmtpClientSimulator();
                smtpClient.Send(account.Address, "*****@*****.**", "Test", "Test message");

                CustomAsserts.AssertRecipientsInDeliveryQueue(0);

                server.WaitForCompletion();

                Assert.IsTrue(server.MessageData.Contains("Test message"));
            }
        }
Esempio n. 12
0
        public void TestDeliverToMyselfOnLocalPortAfterChangedLocalPort()
        {
            TCPIPPorts oPorts = _application.Settings.TCPIPPorts;

            for (int i = 0; i < oPorts.Count; i++)
            {
                TCPIPPort oTestPort = oPorts[i];
                if (oTestPort.Protocol == eSessionType.eSTIMAP)
                {
                    oTestPort.PortNumber = 14300;
                }
                else if (oTestPort.Protocol == eSessionType.eSTSMTP)
                {
                    oTestPort.PortNumber = 11000;
                }
                else if (oTestPort.Protocol == eSessionType.eSTPOP3)
                {
                    oTestPort.PortNumber = 2500;
                }

                oTestPort.Save();
            }

            _application.Stop();
            _application.Start();

            // Set up a server and start listening.
            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                // Add a route so we can connect to localhost.
                TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);

                // Send message to this route.
                var sim = new SmtpClientSimulator(false, 11000);
                sim.Send("*****@*****.**", "*****@*****.**", "Test", "Test message");


                // Wait for the client to disconnect.
                server.WaitForCompletion();

                CustomAsserts.AssertRecipientsInDeliveryQueue(0, false);

                Assert.IsTrue(server.MessageData.Contains("Test message"));
            }

            oPorts.SetDefault();
            _application.Stop();
            _application.Start();
        }
Esempio n. 13
0
        public void TestFatalDeliveryFailure()
        {
            _application.Settings.Logging.Enabled  = true;
            _application.Settings.Logging.LogSMTP  = true;
            _application.Settings.Logging.LogTCPIP = true;
            _application.Settings.Logging.LogDebug = true;

            Assert.AreEqual(0, _status.UndeliveredMessages.Length);

            // No valid recipients...
            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 550;

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                // Add a route so we can conenct to localhost.
                TestSetup.AddRoutePointingAtLocalhost(0, smtpServerPort, false);

                // Send message to this route.
                var smtp       = new SmtpClientSimulator();
                var recipients = new List <string>();
                recipients.Add("*****@*****.**");
                smtp.Send("*****@*****.**", recipients, "Test", "Test message");

                string undeliveredMessages = _status.UndeliveredMessages;

                // Wait for the client to disconnect.
                server.WaitForCompletion();

                // wait for the message to be delivered.
                for (int i = 1; i <= 40; i++)
                {
                    Assert.IsFalse(i == 40);

                    if (_status.UndeliveredMessages.Contains("\[email protected]") || _status.UndeliveredMessages.Length == 0)
                    {
                        break;
                    }

                    Thread.Sleep(250);
                }

                CustomAsserts.AssertRecipientsInDeliveryQueue(0, true);

                string bounceMessage = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test");

                Assert.IsTrue(bounceMessage.Contains("Remote server (127.0.0.1) issued an error."));
                Assert.IsTrue(bounceMessage.Contains("550 [email protected]"));
            }
        }
Esempio n. 14
0
        public void TestTemporaryFailure()
        {
            Assert.AreEqual(0, _status.UndeliveredMessages.Length);

            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 452;

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                // Add a route so we can connect to localhost.
                TestSetup.AddRoutePointingAtLocalhost(2, smtpServerPort, false);

                // Send message to this route.
                var smtp       = new SmtpClientSimulator();
                var recipients = new List <string>();
                recipients.Add("*****@*****.**");
                smtp.Send("*****@*****.**", recipients, "Test", "Test message");

                // Wait for the client to disconnect.
                server.WaitForCompletion();

                Assert.AreNotEqual(0, _status.UndeliveredMessages.Length);
            }

            using (var server = new SmtpServerSimulator(1, smtpServerPort))// Start to listen again.
            {
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                // Deliver the message to the server and then deliver the bounce message.
                CustomAsserts.AssertRecipientsInDeliveryQueue(0, true);

                // Wait for the client to disconnect.
                server.WaitForCompletion();

                Assert.IsFalse(server.Conversation.Contains("\r\nDATA\r\n"));
            }

            // Now the message has bounced.
            string message = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test");

            Assert.IsTrue(message.Contains("452 [email protected]"));
            Assert.IsTrue(message.Contains("Tried 2 time(s)"));
        }
Esempio n. 15
0
        public void TreatRecipientAsExternalDomain()
        {
            int   smtpServerPort = TestSetup.GetNextFreePort();
            Route route          = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false);

            route.TreatRecipientAsLocalDomain = false;
            route.Save();

            var    smtpClientSimulator = new SmtpClientSimulator();
            string result = "";

            CustomAsserts.Throws <DeliveryFailedException>(() => smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result));
            Assert.IsTrue(result.Contains("530 SMTP authentication is required."));
        }
Esempio n. 16
0
        public void DomainAliasesShouldNotRewriteRecipientList()
        {
            DomainAlias oDA = _domain.DomainAliases.Add();

            oDA.AliasName = "dummy-example.com";
            oDA.Save();

            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Set up a server listening on port 250 which accepts email for [email protected]
            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.AddRecipientResult(deliveryResults);
                server.StartListen();


                Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSNone);

                // Now send a message from [email protected] to [email protected].
                // Error scenario:
                // In the recipientlist, otherdomain.com gets rewritten to test.com
                // since there's a domain alias named otherdomain.co on the domain
                // test.com.
                //
                // This should not happen. Otherdomain.com is an alias for test.com,
                // but we shouldn't actually modify the recipient address just because
                // of this.
                var smtpClient = new SmtpClientSimulator();
                smtpClient.Send(account.Address, "*****@*****.**", "Test", "Test message");

                CustomAsserts.AssertRecipientsInDeliveryQueue(0);

                Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 0);

                // This should now be processed via the rule -> route -> external server we've set up.
                server.WaitForCompletion();

                Assert.IsTrue(server.MessageData.Contains("Test message"));
            }
        }
Esempio n. 17
0
        public void TestDeliverySuccess250Recipients()
        {
            Assert.AreEqual(0, _status.UndeliveredMessages.Length);

            // No valid recipients...
            var deliveryResults = new Dictionary <string, int>();

            for (int i = 0; i < 250; i++)
            {
                deliveryResults["user" + i.ToString() + "@dummy-example.com"] = 250;
            }

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(3, smtpServerPort))
            {
                server.AddRecipientResult(deliveryResults);
                server.AddRecipientResult(deliveryResults);
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                // Add a route so we can connect to localhost.
                TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);

                // Send message to this route.
                var smtp       = new SmtpClientSimulator();
                var recipients = new List <string>();

                for (int i = 0; i < 250; i++)
                {
                    recipients.Add("user" + i.ToString() + "@dummy-example.com");
                }

                smtp.Send("*****@*****.**", recipients, "Test", "Test message");

                // Wait for the client to disconnect.
                server.WaitForCompletion();

                CustomAsserts.AssertRecipientsInDeliveryQueue(0, false);

                Assert.IsTrue(server.MessageData.Contains("Test message"));
            }
        }
Esempio n. 18
0
        public void TestUseCaseDeliveryFromPrimaryMXToBackupMX()
        {
            int   smtpServerPort = TestSetup.GetNextFreePort();
            Route route          = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false);

            route.TreatRecipientAsLocalDomain = true;
            route.TreatSenderAsLocalDomain    = false;
            route.Save();

            Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var    smtpClientSimulator = new SmtpClientSimulator();
            string result;

            smtpClientSimulator.Send("*****@*****.**", account1.Address, "Mail 1", "Mail 1", out result);

            string text = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test");

            Assert.IsTrue(text.Contains("Mail 1"));
        }
Esempio n. 19
0
        public void TestSenderAsLocalDomainSendToExternal()
        {
            int   smtpServerPort = TestSetup.GetNextFreePort();
            Route route          = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false);

            route.TreatSenderAsLocalDomain = true;
            route.Save();

            SecurityRange range =
                SingletonProvider <TestSetup> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer");

            range.RequireSMTPAuthLocalToExternal = true;
            range.Save();

            var    smtpClientSimulator = new SmtpClientSimulator();
            string result = "";

            CustomAsserts.Throws <DeliveryFailedException>(() => smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result));
            Assert.IsTrue(result.Contains("530 SMTP authentication is required."));
        }
Esempio n. 20
0
        public void TestFailureAfterReceivedHelloBanner()
        {
            _application.Settings.SMTPNoOfTries         = 3;
            _application.Settings.SMTPMinutesBetweenTry = 60;

            Assert.AreEqual(0, _status.UndeliveredMessages.Length);
            // No valid recipients...
            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.AddRecipientResult(deliveryResults);
                server.SimulatedError = SimulatedErrorType.DisconnectAfterSessionStart;
                server.StartListen();

                // Add a route so we can connect to localhost.
                TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false);

                // Send message to this route.
                var smtp       = new SmtpClientSimulator();
                var recipients = new List <string>();
                recipients.Add("*****@*****.**");
                smtp.Send(_account.Address, recipients, "Test", "Test message");

                // Wait for the client to disconnect.
                server.WaitForCompletion();

                // Force the message to be bounced.
                CustomAsserts.AssertRecipientsInDeliveryQueue(0, true);

                string bounce = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test");

                Assert.IsTrue(bounce.Contains("*****@*****.**"));
                Assert.IsTrue(bounce.Contains("Remote server closed connection."));
                Assert.IsTrue(bounce.Contains("Tried 1 time(s)"));
            }
        }
Esempio n. 21
0
        public void TestSenderAsExternalDomainSendToLocalAccountFail()
        {
            int   smtpServerPort = TestSetup.GetNextFreePort();
            Route route          = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false);

            route.TreatSenderAsLocalDomain = false;
            route.Save();

            SecurityRange range =
                SingletonProvider <TestSetup> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer");

            range.RequireSMTPAuthExternalToLocal = true;
            range.Save();

            Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var    smtpClientSimulator = new SmtpClientSimulator();
            string result;

            CustomAsserts.Throws <DeliveryFailedException>(() => smtpClientSimulator.Send("*****@*****.**", account1.Address, "Mail 1", "Mail 1", out result));
        }
Esempio n. 22
0
        public void TestAuthFailurePasswordInBounce()
        {
            Assert.AreEqual(0, _status.UndeliveredMessages.Length);

            // No valid recipients...
            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.AddRecipientResult(deliveryResults);
                server.SimulatedError = SimulatedErrorType.ForceAuthenticationFailure;
                server.StartListen();

                // Add a route so we can connect to localhost.
                Route route = TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);
                route.RelayerRequiresAuth = true;
                route.RelayerAuthUsername = "******";
                route.SetRelayerAuthPassword("MySecretPassword");

                // Send message to this route.
                var smtp       = new SmtpClientSimulator();
                var recipients = new List <string>();
                recipients.Add("*****@*****.**");
                smtp.Send("*****@*****.**", recipients, "Test", "Test message");

                // Wait for the client to disconnect.
                server.WaitForCompletion();

                CustomAsserts.AssertRecipientsInDeliveryQueue(0);

                string messageText = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test");

                Assert.IsFalse(messageText.Contains("MySecretPassword"));
                Assert.IsTrue(messageText.Contains("<Password removed>"));
            }
        }
Esempio n. 23
0
        public void TestErrorOnMailFrom()
        {
            Assert.AreEqual(0, _status.UndeliveredMessages.Length);

            // No valid recipients...
            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.MailFromResult = 561;
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                // Add a route so we can conenct to localhost.
                TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);

                // Send message to this route.
                var smtp       = new SmtpClientSimulator();
                var recipients = new List <string>();
                recipients.Add("*****@*****.**");
                smtp.Send("*****@*****.**", recipients, "Test", "Test message");

                // Wait for the client to disconnect.
                server.WaitForCompletion();

                CustomAsserts.AssertRecipientsInDeliveryQueue(0);

                string bounceMessage = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test");

                Assert.IsTrue(bounceMessage.Contains("MAIL FROM:<*****@*****.**>"));
                Assert.IsTrue(bounceMessage.Contains("Remote server replied: 561"));
            }
        }
Esempio n. 24
0
        public void TestLargeMessageSuccess()
        {
            Assert.AreEqual(0, _status.UndeliveredMessages.Length);

            // No valid recipients...
            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                // Add a route so we can connect to localhost.
                TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);

                // Send message to this route.
                var messageBody = TestSetup.CreateLargeDummyMailBody();

                var smtp       = new SmtpClientSimulator();
                var recipients = new List <string>();
                recipients.Add("*****@*****.**");
                smtp.Send("*****@*****.**", recipients, "Test", messageBody);

                // Wait for the client to disconnect.
                server.WaitForCompletion();

                Assert.IsTrue(server.Conversation.Contains("\r\nDATA\r\n"));

                CustomAsserts.AssertRecipientsInDeliveryQueue(0, false);

                Assert.IsTrue(server.MessageData.Contains(messageBody));
            }
        }
Esempio n. 25
0
        public void TestSMTPAuthExternalToRouteConfiguredAsLocal()
        {
            // First, make sure hMailServer requires auth.
            SecurityRange range =
                SingletonProvider <TestSetup> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer");

            range.RequireSMTPAuthExternalToExternal = true;
            range.RequireSMTPAuthLocalToExternal    = true;
            range.Save();

            int   smtpServerPort = TestSetup.GetNextFreePort();
            Route route          = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false);

            route.TreatRecipientAsLocalDomain = true;
            route.TreatSenderAsLocalDomain    = true;
            route.Save();

            // Set up the simulating server to listen.
            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;


            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                // Make sure we can't send to this route without using smtp auth.
                var smtpClientSimulator = new SmtpClientSimulator();
                smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1");

                server.WaitForCompletion();

                Assert.IsTrue(server.MessageData.Contains("Mail 1"), server.MessageData);
            }
        }
Esempio n. 26
0
        public void TestSMTPClientTimeout()
        {
            Assert.AreEqual(0, _status.UndeliveredMessages.Length);

            // No valid recipients...
            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.AddRecipientResult(deliveryResults);
                server.SimulatedError = SimulatedErrorType.Sleep15MinutesAfterSessionStart;
                server.SecondsToWaitBeforeTerminate = 20 * 60;
                server.StartListen();

                // Add a route so we can connect to localhost.
                Route route = TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);
                route.RelayerRequiresAuth = true;
                route.RelayerAuthUsername = "******";
                route.SetRelayerAuthPassword("MySecretPassword");

                // Send message to this route.
                var smtp       = new SmtpClientSimulator();
                var recipients = new List <string>();
                recipients.Add("*****@*****.**");
                smtp.Send("*****@*****.**", recipients, "Test", "Test message");

                // Wait for the client to disconnect.
                server.WaitForCompletion();
            }

            CustomAsserts.AssertRecipientsInDeliveryQueue(0);
        }
Esempio n. 27
0
        public void TestFailureAfterDelivery()
        {
            _application.Settings.SMTPNoOfTries         = 3;
            _application.Settings.SMTPMinutesBetweenTry = 60;

            Assert.AreEqual(0, _status.UndeliveredMessages.Length);
            // No valid recipients...
            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.AddRecipientResult(deliveryResults);
                server.QuitResult = 421;
                server.StartListen();

                // Add a route so we can connect to localhost.
                TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false);

                // Send message to this route.
                var smtp       = new SmtpClientSimulator();
                var recipients = new List <string>();
                recipients.Add("*****@*****.**");
                smtp.Send("*****@*****.**", recipients, "Test", "test of error after accepted delivery");

                // Wait for the client to disconnect.
                server.WaitForCompletion();

                CustomAsserts.AssertRecipientsInDeliveryQueue(0);

                Assert.IsTrue(server.MessageData.Contains("test of error after accepted delivery"));
            }
        }
Esempio n. 28
0
        public void TestPartialTemporaryErrorFailure()
        {
            Assert.AreEqual(0, _status.UndeliveredMessages.Length);

            // No valid recipients...
            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;
            deliveryResults["*****@*****.**"] = 250;
            deliveryResults["*****@*****.**"] = 400;

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                // Add a route so we can connect to localhost.
                TestSetup.AddRoutePointingAtLocalhost(2, smtpServerPort, false);

                // Send message to this route.
                var smtp       = new SmtpClientSimulator();
                var recipients = new List <string>();

                recipients.Add("*****@*****.**");
                recipients.Add("*****@*****.**");
                recipients.Add("*****@*****.**");

                smtp.Send("*****@*****.**", recipients, "Test", "Test message");

                // Wait for the client to disconnect.
                server.WaitForCompletion();

                // Trigger a sending of the bounce message.
                CustomAsserts.AssertRecipientsInDeliveryQueue(1);

                Assert.AreEqual(-1, _status.UndeliveredMessages.IndexOf("*****@*****.**"));
                Assert.AreEqual(-1, _status.UndeliveredMessages.IndexOf("*****@*****.**"));
                Assert.AreNotEqual(-1, _status.UndeliveredMessages.IndexOf("*****@*****.**"));

                Assert.IsTrue(server.MessageData.Contains("Test message"));
            }

            // Attempt to deliver the message again.
            using (var server = new SmtpServerSimulator(1, smtpServerPort))
            {
                server.AddRecipientResult(deliveryResults);
                server.StartListen();
                TestSetup.SendMessagesInQueue();
                server.WaitForCompletion();

                //
                CustomAsserts.AssertRecipientsInDeliveryQueue(0);
                string bounceMessage = Pop3ClientSimulator.AssertGetFirstMessageText("*****@*****.**", "test");

                Assert.IsTrue(bounceMessage.Contains("400 [email protected]"));
                Assert.IsTrue(bounceMessage.Contains("Tried 2 time(s)"));

                Assert.IsFalse(bounceMessage.Contains("*****@*****.**"));
                Assert.IsFalse(bounceMessage.Contains("*****@*****.**"));
            }
        }
Esempio n. 29
0
        public void TestDeliverToExternalMimeRecipientsEnabled()
        {
            var messages = new List <string>();

            string message = "From: [email protected]\r\n" +
                             "To: \"Test\" <*****@*****.**>, \"ExternalGuy\" <*****@*****.**>\r\n" +
                             "Subject: Test\r\n" +
                             "\r\n" +
                             "Hello!";

            messages.Add(message);

            int port = TestSetup.GetNextFreePort();

            using (var pop3Server = new Pop3ServerSimulator(1, port, messages))
            {
                pop3Server.StartListen();

                var deliveryResults = new Dictionary <string, int>();
                deliveryResults["*****@*****.**"] = 250;

                int smtpServerPort = TestSetup.GetNextFreePort();
                using (var smtpServer = new SmtpServerSimulator(1, smtpServerPort))
                {
                    smtpServer.AddRecipientResult(deliveryResults);
                    smtpServer.StartListen();

                    // Add a route so we can connect to localhost.
                    Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false);
                    route.TreatSecurityAsLocalDomain = true;
                    route.Save();

                    Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

                    Account account2 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

                    Account catchallAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**",
                                                                                                 "test");

                    _domain.Postmaster = catchallAccount.Address;
                    _domain.Save();

                    FetchAccount fa = account1.FetchAccounts.Add();

                    fa.Enabled             = true;
                    fa.MinutesBetweenFetch = 10;
                    fa.Name                  = "Test";
                    fa.Username              = "******";
                    fa.Password              = "******";
                    fa.UseSSL                = false;
                    fa.ServerAddress         = "localhost";
                    fa.Port                  = port;
                    fa.ProcessMIMERecipients = true;
                    fa.EnableRouteRecipients = true;
                    fa.Save();

                    fa.DownloadNow();

                    pop3Server.WaitForCompletion();

                    fa.Delete();

                    string downloadedMessage1 = Pop3ClientSimulator.AssertGetFirstMessageText(account2.Address, "test");
                    Pop3ClientSimulator.AssertMessageCount(account1.Address, "test", 0);
                    Pop3ClientSimulator.AssertMessageCount(catchallAccount.Address, "test", 0);
                    Assert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1);

                    // Make sure the exernal recipient has received his copy.
                    smtpServer.WaitForCompletion();
                    string messageData = smtpServer.MessageData;
                    Assert.IsTrue(messageData.Contains(messageData), messageData);

                    CustomAsserts.AssertRecipientsInDeliveryQueue(0, false);
                }
            }
        }