Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        public void TestDeliverToExternalMimeRecipientsEnabledRouteAsExternal()
        {
            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();

                // Add a route so we can connect to localhost.
                //Route route = SMTPClientTests.AddRoutePointingAtLocalhost(5, 250, false);
                //route.TreatSecurityAsLocalDomain = false;
                //route.Save();

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

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

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

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

                FetchAccount fa = userAccount.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(recipientAccount1.Address, "test");
                CustomAssert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1);

                TestSetup.AssertRecipientsInDeliveryQueue(0, false);
            }
        }
Esempio n. 3
0
        public void TestDeliverySuccessSingleRecipientMissingQuitResponse()
        {
            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();
                server.SimulatedError = SimulatedErrorType.DisconnectWithoutReplyOnQuit;

                // 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", "DeliverySuccessNoQuitResponse"));

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

                TestSetup.AssertRecipientsInDeliveryQueue(0, false);

                CustomAssert.IsTrue(server.MessageData.Contains("DeliverySuccessNoQuitResponse"));
            }
        }
Esempio n. 4
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 = 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"));
            }
        }
Esempio n. 5
0
        public void TestOnDeliveryFailedVBScript()
        {
            Application application = SingletonProvider <TestSetup> .Instance.GetApp();

            // First set up a script
            string script = "Sub OnDeliveryFailed(oMessage, sRecipient, sErrorMessage)" + Environment.NewLine +
                            " EventLog.Write(\"File: \" & oMessage.FileName) " + Environment.NewLine +
                            " EventLog.Write(\"Recipient: \" & sRecipient) " + Environment.NewLine +
                            " EventLog.Write(\"Error: \" & sErrorMessage) " + Environment.NewLine +
                            " End Sub";

            Scripting scripting = _settings.Scripting;
            string    file      = scripting.CurrentScriptFile;

            TestSetup.WriteFile(file, script);
            scripting.Enabled = true;
            scripting.Reload();

            // Add an account and send a message to it.
            Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            SMTPClientSimulator.StaticSend(oAccount1.Address, "*****@*****.**", "Test", "SampleBody");

            // Make sure that the message is deliverd and bounced.
            TestSetup.AssertRecipientsInDeliveryQueue(0);

            string eventLogText = TestSetup.ReadExistingTextFile(TestSetup.GetEventLogFileName());

            CustomAssert.IsTrue(eventLogText.Contains("File: "));
            CustomAssert.IsTrue(eventLogText.Contains("Recipient: [email protected]"));
            CustomAssert.IsTrue(eventLogText.Contains("No mail servers appear to exists"));
        }
Esempio n. 6
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 = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSSTARTTLSOptional);

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

                TestSetup.AssertRecipientsInDeliveryQueue(0);

                server.WaitForCompletion();

                CustomAssert.IsTrue(server.MessageData.Contains("Test message"));
            }
        }
Esempio n. 7
0
        public void TestBounceMessageSyntax()
        {
            Account senderAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

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

            recipientAccount.MaxSize = 1;
            recipientAccount.Save();

            // Build a 2MB string.
            var builder = new StringBuilder();

            for (int i = 0; i < 11000; i++)
            {
                builder.Append(
                    "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\n");
            }

            string text = builder.ToString();

            SMTPClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "", text);

            // Make sure the recipient did not receive it.
            TestSetup.AssertRecipientsInDeliveryQueue(0);

            // Check the syntax in the bounce message.
            string content = POP3ClientSimulator.AssertGetFirstMessageText(senderAccount.Address, "test");

            // The bounce message should contain the MIME-version.
            CustomAssert.IsTrue(content.Contains("MIME-Version: 1.0"));

            // Lines may not end with space if they are QP-encoded.
            CustomAssert.IsTrue(content.Contains("  Subject:=20"));
        }
Esempio n. 8
0
        public void TestMirrorMultipleRecipientsOver255Chars()
        {
            // Create a test account
            // Fetch the default domain
            var recipients = new List <string>();

            for (int i = 0; i < 20; i++)
            {
                string address = string.Format("mirror{0}@test.com", i);
                SingletonProvider <TestSetup> .Instance.AddAccount(_domain, address, "test");

                recipients.Add(address);
            }

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

            _settings.MirrorEMailAddress   = "*****@*****.**";
            _settings.AddDeliveredToHeader = true;

            // Send 1 messages to this account.
            var oSMTP = new SMTPClientSimulator();

            oSMTP.Send("*****@*****.**", recipients, "INBOX", "Mirror test message");

            POP3ClientSimulator.AssertMessageCount(mirrorAccount.Address, "test", 1);

            string message = POP3ClientSimulator.AssertGetFirstMessageText(mirrorAccount.Address, "test");

            CustomAssert.IsTrue(
                message.Contains(
                    "Delivered-To: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],mirror14@test\r\n"));

            TestSetup.AssertRecipientsInDeliveryQueue(0);
        }
Esempio n. 9
0
        public void ConfirmSingleReturnPathAfterAccountForward()
        {
            // Create a test account
            // Fetch the default domain
            Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

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

            oAccount1.ForwardAddress = oAccount2.Address;
            oAccount1.ForwardEnabled = true;
            oAccount1.Save();

            // Send a message...
            var oSMTP = new SMTPClientSimulator();

            oSMTP.Send("*****@*****.**", oAccount1.Address, "Test message", "This is the body");

            TestSetup.AssertRecipientsInDeliveryQueue(0);
            _application.SubmitEMail();

            // Wait for the auto-reply.
            string text = POP3ClientSimulator.AssertGetFirstMessageText(oAccount2.Address, "test");

            CustomAssert.IsFalse(text.Contains("Return-Path: [email protected]"));
            CustomAssert.IsFalse(text.Contains("Return-Path: [email protected]"));
            CustomAssert.IsTrue(text.Contains("Return-Path: [email protected]"));
        }
Esempio n. 10
0
        public void TestDeliverToMyselfOnLocalPort()
        {
            CustomAssert.AreEqual(0, _status.UndeliveredMessages.Length);

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

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

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

                Thread.Sleep(250);
            }

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

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

            CustomAssert.IsTrue(message.Contains("this would mean connecting to myself."));
        }
Esempio n. 11
0
        public void TestMirrorMultipleRecipients()
        {
            // Create a test account
            // Fetch the default domain
            Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

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

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

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

            _settings.MirrorEMailAddress   = "*****@*****.**";
            _settings.AddDeliveredToHeader = true;

            // Send 5 messages to this account.
            var oSMTP = new SMTPClientSimulator();

            oSMTP.Send("*****@*****.**", new List <string> {
                oAccount1.Address, oAccount2.Address, oAccount3.Address
            },
                       "INBOX", "Mirror test message");

            POP3ClientSimulator.AssertMessageCount(mirrorAccount.Address, "test", 1);

            string message = POP3ClientSimulator.AssertGetFirstMessageText(mirrorAccount.Address, "test");

            CustomAssert.IsTrue(message.Contains("Delivered-To: [email protected],[email protected],[email protected]"));

            TestSetup.AssertRecipientsInDeliveryQueue(0);
        }
Esempio n. 12
0
        public void TestDeliverToServerNotSupportingEHLO()
        {
            CustomAssert.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.
                SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone);

                // Send message to this route.

                if (!SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Test", "Test message"))
                {
                    CustomAssert.Fail("Delivery failed");
                }

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

                TestSetup.AssertRecipientsInDeliveryQueue(0, false);

                CustomAssert.IsTrue(server.MessageData.Contains("Test message"));
            }
        }
Esempio n. 13
0
        public void TestForwardingAndDelete()
        {
            // Create a test account
            // Fetch the default domain
            Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

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

            // Set up account 1 to forward to account2.
            oAccount1.ForwardEnabled      = true;
            oAccount1.ForwardAddress      = "*****@*****.**";
            oAccount1.ForwardKeepOriginal = false;
            oAccount1.Save();

            // Send 2 messages to this account.
            var oSMTP = new SMTPClientSimulator();

            oSMTP.Send("*****@*****.**", "*****@*****.**", "INBOX", "POP3 test message");
            TestSetup.AssertRecipientsInDeliveryQueue(0);
            POP3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 1);

            string domainDir = Path.Combine(_settings.Directories.DataDirectory, "test.com");
            string userDir   = Path.Combine(domainDir, "Forward1");

            string[] dirs = Directory.GetDirectories(userDir);
            foreach (string dir in dirs)
            {
                string[] files = Directory.GetFiles(dir);

                CustomAssert.AreEqual(0, files.Length);
            }
        }
Esempio n. 14
0
        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 = 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"));
            }
        }
Esempio n. 15
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.
                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();

                TestSetup.AssertRecipientsInDeliveryQueue(0, false);

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

            oPorts.SetDefault();
            _application.Stop();
            _application.Start();
        }
Esempio n. 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]"));
            }
        }
Esempio n. 17
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]"));
            }
        }
Esempio n. 18
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"));
            }
        }
Esempio n. 19
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)"));
        }
Esempio n. 20
0
        public void MailFromShouldNotUpdatedLastLogonTime()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "us'*****@*****.**", "test");

            DateTime lastLogonTimeBefore = Convert.ToDateTime(account.LastLogonTime);

            Thread.Sleep(1000);
            SMTPClientSimulator.StaticSend("*****@*****.**", "us'*****@*****.**", "Test", "Test");

            TestSetup.AssertRecipientsInDeliveryQueue(0);
            DateTime lastLogonTimeAfter =
                Convert.ToDateTime(SingletonProvider <TestSetup> .Instance.GetApp().Domains[0].Accounts[0].LastLogonTime);

            CustomAssert.AreEqual(lastLogonTimeBefore, lastLogonTimeAfter);
        }
Esempio n. 21
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);
            }
        }
Esempio n. 22
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"));
            }
        }
Esempio n. 23
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"));
            }
        }
Esempio n. 24
0
        public void TestDeliverySuccess50Recipients()
        {
            CustomAssert.AreEqual(0, _status.UndeliveredMessages.Length);


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

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

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

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

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

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

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

                TestSetup.AssertRecipientsInDeliveryQueue(0, false);

                CustomAssert.IsTrue(server.MessageData.Contains("Test message"));
            }
        }
Esempio n. 25
0
        public void BounceMessageShouldContainSubjectAndDate()
        {
            Account senderAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

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

            recipientAccount.MaxSize = 1;
            recipientAccount.Save();

            // Make sure that no bounce is sent.
            SMTPClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "MySubject", "Test");
            POP3ClientSimulator.AssertGetFirstMessageText(recipientAccount.Address, "test");

            // Build a 2MB string.
            var builder = new StringBuilder();

            for (int i = 0; i < 11000; i++)
            {
                builder.Append(
                    "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\n");
            }
            string text = builder.ToString();

            SMTPClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "Test subject", text);

            // Make sure the recipient did not receive it.
            TestSetup.AssertRecipientsInDeliveryQueue(0);
            POP3ClientSimulator.AssertMessageCount(recipientAccount.Address, "test", 0);
            SingletonProvider <TestSetup> .Instance.AssertFilesInUserDirectory(recipientAccount, 0);

            // Make sure it bounced.
            string content = POP3ClientSimulator.AssertGetFirstMessageText(senderAccount.Address, "test");

            CustomAssert.IsTrue(content.Contains("Inbox is full"));
            CustomAssert.IsTrue(content.Contains("Subject: Test subject"));

            // Make sure body contains year.
            int bodyStartPos = content.IndexOf("\r\n\r\n");
            int yearPos      = content.IndexOf(DateTime.Now.Year.ToString(), bodyStartPos);

            CustomAssert.IsTrue(yearPos >= 0);
        }
Esempio n. 26
0
        public void TestSMTPAuthExternalToLocal()
        {
            SecurityRange range =
                SingletonProvider <TestSetup> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer");

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

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

            var oSMTP = new SMTPClientSimulator();

            CustomAssert.IsFalse(oSMTP.Send("*****@*****.**", account1.Address, "Mail 1", "Mail 1"));

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

            CustomAssert.IsTrue(oSMTP.Send("*****@*****.**", account1.Address, "Mail 1", "Mail 1"));
            TestSetup.AssertRecipientsInDeliveryQueue(0);
        }
Esempio n. 27
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);
            }
        }
Esempio n. 28
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)"));
            }
        }
Esempio n. 29
0
        public void TestWithVirus()
        {
            _antiVirus.ClamAVEnabled = true;
            TestSetup.DeleteCurrentDefaultLog();

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

            string firstPart  = @"X5O!P%@AP[4\PZX54(P^)7CC)7}";
            string secondPart = @"$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*";

            CustomAssert.IsTrue(SMTPClientSimulator.StaticSend(account1.Address, account1.Address, "Mail 1",
                                                               firstPart + secondPart));

            TestSetup.AssertRecipientsInDeliveryQueue(0);
            POP3ClientSimulator.AssertMessageCount(account1.Address, "test", 0);

            string defaultLog = TestSetup.ReadCurrentDefaultLog();

            CustomAssert.IsTrue(defaultLog.Contains("Connecting to ClamAV"));
            CustomAssert.IsTrue(defaultLog.Contains("Message deleted (contained virus Eicar-Test-Signature)"));
        }
Esempio n. 30
0
        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>"));
            }
        }