Exemplo 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"));
            }
        }
Exemplo 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"));
            }
        }
        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."));
            }
        }
Exemplo n.º 4
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");
            }
        }
Exemplo n.º 5
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"));
            }
        }
        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"));
            }
        }
Exemplo n.º 7
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("*****@*****.**");
                smtp.Send("*****@*****.**", recipients, "Test", body);

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

                CustomAsserts.AssertRecipientsInDeliveryQueue(0);

                return(messageData);
            }
        }
Exemplo n.º 8
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"));
            }
        }
Exemplo n.º 9
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."));
            }
        }
Exemplo n.º 10
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"));
            }
        }
Exemplo n.º 11
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");
            }
        }
Exemplo 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();
        }
Exemplo 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]"));
            }
        }
Exemplo n.º 14
0
        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]"));
            }
        }
Exemplo n.º 15
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)"));
        }
Exemplo n.º 16
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>()
                {
                    "*****@*****.**",
                    "*****@*****.**",
                    "*****@*****.**",
                    "*****@*****.**"
                };

                smtpClient.Send("*****@*****.**", recipients, "Test", "Test message");
                CustomAsserts.AssertRecipientsInDeliveryQueue(0);

                server.WaitForCompletion();

                Assert.IsTrue(server.MessageData.Contains("Test message"));
                Assert.AreEqual(deliveryResults.Count, server.RcptTosReceived);
            }
        }
Exemplo n.º 17
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"));
            }
        }
Exemplo n.º 18
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();
                smtpClient.Send("*****@*****.**", "*****@*****.**", "Test", "Test message");
                CustomAsserts.AssertRecipientsInDeliveryQueue(0);

                server.WaitForCompletion();

                Assert.IsTrue(server.MessageData.Contains("Test message"));
            }
        }
Exemplo n.º 19
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"));
            }
        }
Exemplo n.º 20
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");

                smtpClient.Send(senderAccount.Address, recipients, "Test", "Test message");
                CustomAsserts.AssertRecipientsInDeliveryQueue(0);

                server.WaitForCompletion();

                Assert.IsTrue(server.MessageData.Contains("Test message"));
                Assert.AreEqual(deliveryResults.Count, server.RcptTosReceived);
            }
        }
Exemplo n.º 21
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)"));
            }
        }
Exemplo n.º 22
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();
                smtpClient.Send("*****@*****.**", "*****@*****.**", "Test", "Test message");
                CustomAsserts.AssertRecipientsInDeliveryQueue(0);

                server.WaitForCompletion();

                Assert.IsTrue(server.MessageData.Contains("Test message"));
            }
        }
Exemplo n.º 23
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>"));
            }
        }
Exemplo n.º 24
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);
            }
        }
Exemplo n.º 25
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));
            }
        }
Exemplo n.º 26
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"));
            }
        }
Exemplo n.º 27
0
        public void TestSMTPClient()
        {
            Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

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

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

                CustomAsserts.AssertRecipientsInDeliveryQueue(0);

                string undeliveredMessages = _status.UndeliveredMessages;

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

                CustomAsserts.AssertRecipientsInDeliveryQueue(0);

                EnsureNoPassword();
            }
        }
Exemplo n.º 28
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"));
            }
        }
Exemplo n.º 29
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);
        }
Exemplo n.º 30
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);
                }
            }
        }