public void TreatRecipientAsLocalDomain()
        {
            int   smtpServerPort = TestSetup.GetNextFreePort();
            Route route          = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false);

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

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

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

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

                var    oSMTP = new SMTPClientSimulator();
                string result;
                CustomAssert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result));

                server.WaitForCompletion();

                server.MessageData.Contains("Mail 1");
            }
        }
Exemple #2
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"));
            }
        }
        public void TreatRecipientAsExternalDomainPermitted()
        {
            int   smtpServerPort = TestSetup.GetNextFreePort();
            Route route          = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false);

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

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

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

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

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

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

                var    oSMTP = new SMTPClientSimulator();
                string result;
                CustomAssert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result));

                server.WaitForCompletion();

                server.MessageData.Contains("Mail 1");
            }
        }
        public void TestSenderAsLocalDomainSendToLocalAccountPass()
        {
            int   smtpServerPort = TestSetup.GetNextFreePort();
            Route route          = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false);

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

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

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

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

            var    oSMTP = new SMTPClientSimulator();
            string result;

            CustomAssert.IsTrue(oSMTP.Send("*****@*****.**", account1.Address, "Mail 1", "Mail 1", out result));

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

            CustomAssert.IsTrue(text.Contains("Mail 1"));
        }
        public void TestUseCase3DeliveryFromExternalUserToPrimaryViaBackup()
        {
            hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, 250, false);
            route.TreatRecipientAsLocalDomain = true;
            route.TreatSenderAsLocalDomain    = false;
            route.Save();

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

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

            SMTPServerSimulator server = new SMTPServerSimulator(1, 250);

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

            SMTPClientSimulator oSMTP = new SMTPClientSimulator();
            string result;

            Assert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result));

            server.WaitForCompletion();

            server.MessageData.Contains("Mail 1");
        }
Exemple #6
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"));
            }
        }
        public void TestSMTPAuthExternalToRouteConfiguredAsLocal()
        {
            // First, make sure hMailServer requires auth.
            hMailServer.SecurityRange range = SingletonProvider <Utilities> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer");

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


            hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, 250, false);
            route.TreatRecipientAsLocalDomain = true;
            route.TreatSenderAsLocalDomain    = true;
            route.Save();

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

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

            SMTPServerSimulator server = new SMTPServerSimulator(1, 250);

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

            // Make sure we can't send to this route without using smtp auth.
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            Assert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1"));

            server.WaitForCompletion();

            Assert.IsTrue(server.MessageData.Contains("Mail 1"), server.MessageData);
        }
        public void TestDeliverToExternalMimeRecipientsEnabledRouteAsExternal()
        {
            List <string> 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       = 1110;
            POP3Server pop3Server = new POP3Server(1, port, messages);

            pop3Server.StartListen();

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

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

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

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

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

            hMailServer.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 = POP3Simulator.AssertGetFirstMessageText(recipientAccount1.Address, "test");

            Assert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1);

            Utilities.AssertRecipientsInDeliveryQueue(0, false);
        }
        public void TreatRecipientAsExternalDomain()
        {
            hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, 250, false);
            route.TreatRecipientAsLocalDomain = false;
            route.Save();

            SMTPClientSimulator oSMTP = new SMTPClientSimulator();
            string result;

            Assert.IsFalse(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result));
            Assert.IsTrue(result.Contains("530 SMTP authentication is required."));
        }
        public void TreatRecipientAsExternalDomain()
        {
            int   smtpServerPort = TestSetup.GetNextFreePort();
            Route route          = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false);

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

            var    oSMTP = new SMTPClientSimulator();
            string result;

            CustomAssert.IsFalse(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result));
            CustomAssert.IsTrue(result.Contains("530 SMTP authentication is required."));
        }
        public void TestSenderAsLocalDomainSendToExternal()
        {
            hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, 250, false);
            route.TreatSenderAsLocalDomain = true;
            route.Save();

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

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

            SMTPClientSimulator oSMTP = new SMTPClientSimulator();
            string result;

            Assert.IsFalse(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result));
            Assert.IsTrue(result.Contains("530 SMTP authentication is required."));
        }
        public void TestSenderAsExternalDomainSendToLocalAccountFail()
        {
            hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, 250, false);
            route.TreatSenderAsLocalDomain = false;
            route.Save();

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

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

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

            SMTPClientSimulator oSMTP = new SMTPClientSimulator();
            string result;

            Assert.IsFalse(oSMTP.Send("*****@*****.**", account1.Address, "Mail 1", "Mail 1", out result));
        }
        public void TestUseCaseDeliveryFromPrimaryMXToBackupMX()
        {
            hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, 250, false);
            route.TreatRecipientAsLocalDomain = true;
            route.TreatSenderAsLocalDomain    = false;
            route.Save();

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

            SMTPClientSimulator oSMTP = new SMTPClientSimulator();
            string result;

            Assert.IsTrue(oSMTP.Send("*****@*****.**", account1.Address, "Mail 1", "Mail 1", out result));

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

            Assert.IsTrue(text.Contains("Mail 1"));
        }
Exemple #14
0
        public void TestDeliverToExternalMimeRecipientsEnabled()
        {
            var messages = new List <string>();

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

            messages.Add(message);

            int port = TestSetup.GetNextFreePort();

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

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

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

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

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

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

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

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

                    FetchAccount fa = account1.FetchAccounts.Add();

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

                    fa.DownloadNow();

                    pop3Server.WaitForCompletion();

                    fa.Delete();

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

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

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