public void DoNotUseStartTlsIfNotEnabledAndNotAvailable()
        {
            // No valid recipients...
             var deliveryResults = new Dictionary<string, int>();
             deliveryResults["*****@*****.**"] = 250;

             int smtpServerPort = TestSetup.GetNextFreePort();
             using (var server = new SMTPServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSNone))
             {
            server.AddRecipientResult(deliveryResults);
            server.StartListen();

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

            // Send message to this route.
            var smtp = new SMTPClientSimulator();
            if (!smtp.Send("*****@*****.**", "*****@*****.**", "Test", "Test message"))
               CustomAssert.Fail("Delivery failed");

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

            TestSetup.AssertRecipientsInDeliveryQueue(0, false);

            Assert.IsNotNullOrEmpty(server.MessageData);

            CustomAssert.IsFalse(TestSetup.DefaultLogContains("220 Ready to start TLS"));
             }
        }
        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 = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSSTARTTLSRequired);

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

            TestSetup.AssertRecipientsInDeliveryQueue(0);

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

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

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

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

            // Add a route pointing at localhost
            Route route = _settings.Routes.Add();
            route.DomainName = "test.com";
            route.TargetSMTPHost = "localhost";
            route.TargetSMTPPort = smtpServerPort;
            route.NumberOfTries = 1;
            route.MinutesBetweenTry = 5;
            route.TreatRecipientAsLocalDomain = true;
            route.TreatSenderAsLocalDomain = true;
            route.AllAddresses = true;
            route.Save();

            var smtpClient = new SMTPClientSimulator();

            var recipients = new List<string>()
               {
                  "*****@*****.**",
                  "*****@*****.**",
                  "*****@*****.**",
                  "*****@*****.**"
               };

            CustomAssert.IsTrue(smtpClient.Send("*****@*****.**", recipients, "Test", "Test message"));
            TestSetup.AssertRecipientsInDeliveryQueue(0);

            server.WaitForCompletion();

            CustomAssert.IsTrue(server.MessageData.Contains("Test message"));
            CustomAssert.AreEqual(deliveryResults.Count, server.RcptTosReceived);
             }
        }
        public void TestAuthFailurePasswordInBounce()
        {
            CustomAssert.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 = 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("*****@*****.**");
            CustomAssert.IsTrue(smtp.Send("*****@*****.**", recipients, "Test", "Test message"));

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

            TestSetup.AssertRecipientsInDeliveryQueue(0);

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

            CustomAssert.IsFalse(messageText.Contains("MySecretPassword"));
            CustomAssert.IsTrue(messageText.Contains("<Password removed>"));
             }
        }
示例#5
0
        public void RoutesShouldHaveHigherPrioThanSMTPRelay()
        {
            // Set up a server listening on port 250 which accepts email for [email protected]
             var deliveryResults = new Dictionary<string, int>();
             deliveryResults["*****@*****.**"] = 250;

             // We set the SMTP relayer here, but this should be ignored since the recipient's
             // address matches a route set up (test.com).
             _application.Settings.SMTPRelayer = "example.com";

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

            // Add a route pointing at localhost
            Route route = _settings.Routes.Add();
            route.DomainName = "test.com";
            route.TargetSMTPHost = "localhost";
            route.TargetSMTPPort = smtpServerPort;
            route.NumberOfTries = 1;
            route.MinutesBetweenTry = 5;
            route.TreatRecipientAsLocalDomain = true;
            route.TreatSenderAsLocalDomain = true;
            route.AllAddresses = false;
            route.Save();

            // Make sure only the specific user is valid.
            RouteAddress routeAddress = route.Addresses.Add();
            routeAddress.Address = "user@" + _domain.Name;
            routeAddress.Save();

            SingletonProvider<TestSetup>.Instance.AddAlias(_domain, "*****@*****.**", "*****@*****.**");

            var smtpClient = new SMTPClientSimulator();
            CustomAssert.IsTrue(smtpClient.Send("*****@*****.**", "*****@*****.**", "Test", "Test message"));
            TestSetup.AssertRecipientsInDeliveryQueue(0);

            server.WaitForCompletion();

            CustomAssert.IsTrue(server.MessageData.Contains("Test message"));
             }
        }
        public void TestFailureAfterDelivery()
        {
            _application.Settings.SMTPNoOfTries = 3;
             _application.Settings.SMTPMinutesBetweenTry = 60;

             CustomAssert.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.
            AddRoutePointingAtLocalhost(5, smtpServerPort, false);

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

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

            TestSetup.AssertRecipientsInDeliveryQueue(0);

            CustomAssert.IsTrue(server.MessageData.Contains("test of error after accepted delivery"));
             }
        }
示例#7
0
        public void TestSendExternalToExternalPermitted()
        {
            SecurityRange 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["*****@*****.**"] = 250;

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

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

            var oSMTP = new SMTPClientSimulator();
            CustomAssert.IsTrue(oSMTP.Send("*****@*****.**",
                                           "*****@*****.**", "Mail 1", "Test message"));

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

            CustomAssert.IsTrue(server.MessageData.Contains("Test message"));
             }
        }
示例#8
0
        public void SmtpRelayShouldConsolidateRecipients()
        {
            // Set up a server listening on port 250 which accepts email for [email protected]
             var deliveryResults = new Dictionary<string, int>();
             deliveryResults["*****@*****.**"] = 250;
             deliveryResults["*****@*****.**"] = 250;
             deliveryResults["*****@*****.**"] = 250;
             deliveryResults["*****@*****.**"] = 250;

             int smtpServerPort = TestSetup.GetNextFreePort();
             using (var server = new SMTPServerSimulator(1, smtpServerPort))
             {
            _application.Settings.SMTPRelayer = "localhost";
            _application.Settings.SMTPRelayerPort = smtpServerPort;

            server.AddRecipientResult(deliveryResults);
            server.StartListen();

            var smtpClient = new SMTPClientSimulator();

            var recipients = new List<string>()
               {
                  "*****@*****.**",
                  "*****@*****.**",
                  "*****@*****.**",
                  "*****@*****.**"
               };

            Account senderAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");
            CustomAssert.IsTrue(smtpClient.Send(senderAccount.Address, recipients, "Test", "Test message"));
            TestSetup.AssertRecipientsInDeliveryQueue(0);

            server.WaitForCompletion();

            CustomAssert.IsTrue(server.MessageData.Contains("Test message"));
            CustomAssert.AreEqual(deliveryResults.Count, server.RcptTosReceived);
             }
        }
示例#9
0
        public void TreatRecipientAsLocalDomain()
        {
            int smtpServerPort = TestSetup.GetNextFreePort();
             Route route = SMTPClientTests.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 oSMTP = new SMTPClientSimulator();
            string result;
            Assert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result));

            server.WaitForCompletion();

            server.MessageData.Contains("Mail 1");
             }
        }
示例#10
0
        public void TestPartialTemporaryErrorFailure()
        {
            CustomAssert.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.
            AddRoutePointingAtLocalhost(2, smtpServerPort, false);

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

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

            if (!smtp.Send("*****@*****.**", recipients, "Test", "Test message"))
               CustomAssert.Fail("Delivery failed");

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

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

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

            CustomAssert.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();

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

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

            CustomAssert.IsFalse(bounceMessage.Contains("*****@*****.**"));
            CustomAssert.IsFalse(bounceMessage.Contains("*****@*****.**"));
             }
        }
示例#11
0
        public void TestDeliveryAttempts()
        {
            // Add an account
             Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             Account adminAccount = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             // Set up a rule to forward from account1 to 2 and 3.
             Rule oRule = _application.Rules.Add();
             oRule.Name = "Criteria test";
             oRule.Active = true;
             oRule.UseAND = true;

             RuleCriteria oRuleCriteria = oRule.Criterias.Add();
             oRuleCriteria.UsePredefined = true;
             oRuleCriteria.PredefinedField = eRulePredefinedField.eFTDeliveryAttempts;
             oRuleCriteria.MatchType = eRuleMatchType.eMTEquals;
             oRuleCriteria.MatchValue = "2";
             oRuleCriteria.Save();

             // The second time we try to deliver an email, forward a copy to the admin!
             RuleAction oRuleAction = oRule.Actions.Add();
             oRuleAction.Type = eRuleActionType.eRAForwardEmail;
             oRuleAction.To = adminAccount.Address;
             oRuleAction.Save();

             // And then delete it.
             oRuleAction = oRule.Actions.Add();
             oRuleAction.Type = eRuleActionType.eRADeleteEmail;
             oRuleAction.Save();

             // Save the rule in the database
             oRule.Save();

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

             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.
            SMTPClientTests.AddRoutePointingAtLocalhost(2, smtpServerPort, false);

            var oSMTP = new SMTPClientSimulator();

            // Test to send the message to account 1. Make sure a copy is created by this rule.
            oSMTP.Send(account.Address, new List<string> {"*****@*****.**"}, "Test", "Test message.");

            smtpServer.WaitForCompletion();
             }

             TestSetup.AssertRecipientsInDeliveryQueue(0, true);

             string first = POP3ClientSimulator.AssertGetFirstMessageText(adminAccount.Address, "test");

             CustomAssert.IsTrue(first.Contains("X-hMailServer-LoopCount: 1"), first);

             POP3ClientSimulator.AssertMessageCount(account.Address, "test", 0);
        }
示例#12
0
        public void TestMultipleHostsTemporaryFailure()
        {
            CustomAssert.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 = AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort);

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

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

            if (!smtp.Send("*****@*****.**", recipients, "Test", "Test message"))
               CustomAssert.Fail("Delivery failed");

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

             TestSetup.AssertRecipientsInDeliveryQueue(1);

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

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

            TestSetup.AssertRecipientsInDeliveryQueue(0, true);

            server.WaitForCompletion();

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

            CustomAssert.IsFalse(bounceMessage.Contains("*****@*****.**"));
            CustomAssert.IsFalse(bounceMessage.Contains("*****@*****.**"));
            CustomAssert.IsTrue(bounceMessage.Contains("*****@*****.**"));
            CustomAssert.IsTrue(bounceMessage.Contains("499 [email protected]"));
            CustomAssert.IsTrue(bounceMessage.Contains("Tried 2 time(s)"));
             }
        }
示例#13
0
        public void TestMultipleHostsTemporaryFailureDeliveryOnSecondServer()
        {
            CustomAssert.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["*****@*****.**"] = 250;
             deliveryResultsSecond["*****@*****.**"] = 250;
             deliveryResultsSecond["*****@*****.**"] = 250;

             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.
            AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort);

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

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

            if (!smtp.Send("*****@*****.**", recipients, "Test", "Accepted message"))
               CustomAssert.Fail("Delivery failed");

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

            // Trigger a sending of the bounce message.
            TestSetup.AssertRecipientsInDeliveryQueue(0);

            CustomAssert.IsTrue(server.MessageData.Contains("Accepted message"));
             }
        }
示例#14
0
        public void TestMultipleHostsHalfDeliveryOnFirstPermanentOnSecond()
        {
            CustomAssert.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.
            AddRoutePointingAtLocalhostMultipleHosts(1, smtpServerPort);

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

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

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

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

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

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

            CustomAssert.IsFalse(bounceMessage.Contains("RCPT TO:<*****@*****.**>"));
            CustomAssert.IsFalse(bounceMessage.Contains("RCPT TO:<*****@*****.**>"));
            CustomAssert.IsTrue(bounceMessage.Contains("RCPT TO:<*****@*****.**>"));
            CustomAssert.IsTrue(bounceMessage.Contains("500 [email protected]"));
             }
        }
示例#15
0
        public void TestLargeMessageSuccess()
        {
            CustomAssert.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.
            AddRoutePointingAtLocalhost(5, smtpServerPort, false);

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

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

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

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

            TestSetup.AssertRecipientsInDeliveryQueue(0, false);

            CustomAssert.IsTrue(server.MessageData.Contains(messageBody));
             }
        }
示例#16
0
        public void TestFatalDeliveryFailure()
        {
            _application.Settings.Logging.Enabled = true;
             _application.Settings.Logging.LogSMTP = true;
             _application.Settings.Logging.LogTCPIP = true;
             _application.Settings.Logging.LogDebug = true;

             CustomAssert.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.
            AddRoutePointingAtLocalhost(0, smtpServerPort, false);

            // Send message to this route.
            var smtp = new SMTPClientSimulator();
            var recipients = new List<string>();
            recipients.Add("*****@*****.**");
            CustomAssert.IsTrue(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++)
            {
               CustomAssert.IsFalse(i == 40);

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

               Thread.Sleep(250);
            }

            TestSetup.AssertRecipientsInDeliveryQueue(0, true);

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

            CustomAssert.IsTrue(bounceMessage.Contains("Remote server (127.0.0.1) issued an error."));
            CustomAssert.IsTrue(bounceMessage.Contains("550 [email protected]"));
             }
        }
示例#17
0
        private string SendMessage(string body)
        {
            SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

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

             int port = TestSetup.GetNextFreePort();
             using (var server = new SMTPServerSimulator(1, port))
             {
            server.SecondsToWaitBeforeTerminate = 60;
            server.AddRecipientResult(deliveryResults);
            server.StartListen();

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

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

            // Wait for the client to disconnect.
            server.WaitForCompletion();
            string messageData = server.MessageData;

            TestSetup.AssertRecipientsInDeliveryQueue(0);

            return messageData;
             }
        }
示例#18
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 = SMTPClientTests.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 oSMTP = new SMTPClientSimulator();
            Assert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1"));

            server.WaitForCompletion();

            Assert.IsTrue(server.MessageData.Contains("Mail 1"), server.MessageData);
             }
        }
示例#19
0
        public void TestPermanentFailure()
        {
            CustomAssert.AreEqual(0, _status.UndeliveredMessages.Length);

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

             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.
            AddRoutePointingAtLocalhost(5, smtpServerPort, false);

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

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

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

             TestSetup.AssertRecipientsInDeliveryQueue(0);

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

             CustomAssert.IsTrue(bounce.Contains("Remote server replied: 542 [email protected]"));
        }
示例#20
0
        public void TestFailureAfterReceivedHelloBanner()
        {
            _application.Settings.SMTPNoOfTries = 3;
             _application.Settings.SMTPMinutesBetweenTry = 60;

             CustomAssert.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.
            AddRoutePointingAtLocalhost(1, smtpServerPort, false);

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

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

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

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

            CustomAssert.IsTrue(bounce.Contains("*****@*****.**"));
            CustomAssert.IsTrue(bounce.Contains("Remote server closed connection."));
            CustomAssert.IsTrue(bounce.Contains("Tried 1 time(s)"));
             }
        }
示例#21
0
        public void ActionSendUsingRoute()
        {
            int smtpServerPort = TestSetup.GetNextFreePort();

             // add an account to send from
             Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

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

             // Add a global send-using-route rule
             Rule oRule = _application.Rules.Add();
             oRule.Name = "Send using route";
             oRule.Active = true;

             RuleCriteria oRuleCriteria = oRule.Criterias.Add();
             oRuleCriteria.UsePredefined = false;
             oRuleCriteria.HeaderField = "Subject";
             oRuleCriteria.MatchType = eRuleMatchType.eMTContains;
             oRuleCriteria.MatchValue = "TestString";
             oRuleCriteria.Save();

             // Add action
             RuleAction oRuleAction = oRule.Actions.Add();
             oRuleAction.Type = eRuleActionType.eRASendUsingRoute;
             oRuleAction.RouteID = route.ID;
             oRuleAction.Save();

             oRule.Save();

             // Send message and confirm that the route does not affect it.
             var smtp = new SMTPClientSimulator();
             var recipients = new List<string>();
             recipients.Add("*****@*****.**");
             if (!smtp.Send("*****@*****.**", recipients, "Test", "Test message"))
            CustomAssert.Fail("Delivery failed");
             string message = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test");
             CustomAssert.IsTrue(message.Contains("Test message"));

             // Send a message and confirm that the rule affects it.
             var deliveryResults = new Dictionary<string, int>();
             deliveryResults["*****@*****.**"] = 550;

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

            // Send the actual message
            recipients = new List<string>();
            recipients.Add("*****@*****.**");
            if (!smtp.Send("*****@*****.**", recipients, "TestString", "Test message"))
               CustomAssert.Fail("Delivery failed");

            server.WaitForCompletion();
             }

             // Submit the bounce message...
             TestSetup.AssertRecipientsInDeliveryQueue(0);

             // Download it.
             message = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test");

             CustomAssert.IsTrue(message.Contains("550"));
             CustomAssert.IsTrue(message.Contains("*****@*****.**"));
        }
示例#22
0
        public void TestSMTPClientTimeout()
        {
            CustomAssert.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 = 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("*****@*****.**");
            CustomAssert.IsTrue(smtp.Send("*****@*****.**", recipients, "Test", "Test message"));

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

             TestSetup.AssertRecipientsInDeliveryQueue(0);
        }
示例#23
0
        public void TreatRecipientAsExternalDomainPermitted()
        {
            int smtpServerPort = TestSetup.GetNextFreePort();
             Route route = SMTPClientTests.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 oSMTP = new SMTPClientSimulator();
            string result;
            Assert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result));

            server.WaitForCompletion();

            server.MessageData.Contains("Mail 1");
             }
        }
示例#24
0
        public void TestTemporaryFailure()
        {
            CustomAssert.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.
            AddRoutePointingAtLocalhost(2, smtpServerPort, false);

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

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

            CustomAssert.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.
            TestSetup.AssertRecipientsInDeliveryQueue(0, true);

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

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

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

             CustomAssert.IsTrue(message.Contains("452 [email protected]"));
             CustomAssert.IsTrue(message.Contains("Tried 2 time(s)"));
        }
示例#25
0
        public void TestSMTPClient()
        {
            Account account1 = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             CustomAssert.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 connect to localhost.
            AddRoutePointingAtLocalhostWithAuth(0, smtpServerPort);

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

            TestSetup.AssertRecipientsInDeliveryQueue(0);

            string undeliveredMessages = _status.UndeliveredMessages;

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

            TestSetup.AssertRecipientsInDeliveryQueue(0);

            EnsureNoPassword();
             }
        }
示例#26
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 POP3Server(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 = SMTPClientTests.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);
               CustomAssert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1);

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

               TestSetup.AssertRecipientsInDeliveryQueue(0, false);
            }
             }
        }
示例#27
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 = SMTPClientTests.AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort);

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

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

            CustomAssert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Test", "Test"));

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

            string log = TestSetup.ReadCurrentDefaultLog();
            CustomAssert.IsTrue(log.Contains("Truncating MX server list."));
             }
        }
示例#28
0
        public void RoutesShouldSupportWildcardDomain()
        {
            // 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();

            // Add a route pointing at localhost
            Route route = _settings.Routes.Add();
            route.DomainName = "*.example.com";
            route.TargetSMTPHost = "localhost";
            route.TargetSMTPPort = smtpServerPort;
            route.NumberOfTries = 1;
            route.MinutesBetweenTry = 5;
            route.TreatRecipientAsLocalDomain = true;
            route.TreatSenderAsLocalDomain = true;
            route.AllAddresses = true;
            route.Save();

            // Make sure only the specific user is valid.
            RouteAddress routeAddress = route.Addresses.Add();
            routeAddress.Address = "user@" + _domain.Name;
            routeAddress.Save();

            var smtpClient = new SMTPClientSimulator();
            CustomAssert.IsTrue(smtpClient.Send("*****@*****.**", "*****@*****.**", "Test", "Test message"));
            TestSetup.AssertRecipientsInDeliveryQueue(0);

            server.WaitForCompletion();

            CustomAssert.IsTrue(server.MessageData.Contains("Test message"));
             }
        }
示例#29
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 = SMTPClientTests.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();
            CustomAssert.IsTrue(smtpClient.Send(account.Address, "*****@*****.**", "Test", "Test message"));

            TestSetup.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();

            CustomAssert.IsTrue(server.MessageData.Contains("Test message"));
             }
        }
示例#30
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 = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSNone);
            route.TargetSMTPHost = "127.0.0.1";
            route.Save();

            var smtpSimulator = new SMTPClientSimulator();
            CustomAssert.IsTrue(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 = TestSetup.ReadCurrentDefaultLog();

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