Exemple #1
0
        public void TestMultipleHostsLimitMXHosts()
        {
            _settings.MaxNumberOfMXHosts = 1;

            // 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.
                Route route = TestSetup.AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort);

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

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

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

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

                string log = LogHandler.ReadCurrentDefaultLog();
                Assert.IsTrue(log.Contains("Truncating MX server list."));
            }
        }
        public void TestMultipleHostsHalfDeliveryOnFirstPermanentOnSecond()
        {
            Assert.AreEqual(0, _status.UndeliveredMessages.Length);

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

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

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

            deliveryResultsSecond["*****@*****.**"] = 550;
            deliveryResultsSecond["*****@*****.**"] = 550;
            deliveryResultsSecond["*****@*****.**"] = 500;

            int smtpServerPort = TestSetup.GetNextFreePort();

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


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

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

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

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

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

                // Trigger a sending of the bounce message.
                CustomAsserts.AssertRecipientsInDeliveryQueue(0, true);

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

                Assert.IsFalse(bounceMessage.Contains("RCPT TO:<*****@*****.**>"));
                Assert.IsFalse(bounceMessage.Contains("RCPT TO:<*****@*****.**>"));
                Assert.IsTrue(bounceMessage.Contains("RCPT TO:<*****@*****.**>"));
                Assert.IsTrue(bounceMessage.Contains("500 [email protected]"));
            }
        }
        public void TestMultipleHostsTemporaryFailure()
        {
            Assert.AreEqual(0, _status.UndeliveredMessages.Length);

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

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

            int smtpServerPort = TestSetup.GetNextFreePort();

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

                // Add a route so we can connect to localhost.
                Route route = TestSetup.AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort);

                // 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();
            }


            CustomAsserts.AssertRecipientsInDeliveryQueue(1);

            // Check so that only user 3 remains in the queue.
            Assert.AreEqual(-1, _status.UndeliveredMessages.IndexOf("*****@*****.**"));
            Assert.AreEqual(-1, _status.UndeliveredMessages.IndexOf("*****@*****.**"));
            Assert.AreNotEqual(-1, _status.UndeliveredMessages.IndexOf("*****@*****.**"));

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

                CustomAsserts.AssertRecipientsInDeliveryQueue(0, true);

                server.WaitForCompletion();

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

                Assert.IsFalse(bounceMessage.Contains("*****@*****.**"));
                Assert.IsFalse(bounceMessage.Contains("*****@*****.**"));
                Assert.IsTrue(bounceMessage.Contains("*****@*****.**"));
                Assert.IsTrue(bounceMessage.Contains("499 [email protected]"));
                Assert.IsTrue(bounceMessage.Contains("Tried 2 time(s)"));
            }
        }