コード例 #1
0
        public void TestAuthFailurePasswordInBounce()
        {
            Assert.AreEqual(0, _status.UndeliveredMessages.Length);

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

             SMTPServerSimulator server = new SMTPServerSimulator(1, 250);
             server.AddRecipientResult(deliveryResults);
             server.SimulatedError = SimulatedErrorType.ForceAuthenticationFailure;
             server.StartListen();

             // Add a route so we can connect to localhost.
             hMailServer.Route route = AddRoutePointingAtLocalhost(5, 250, false);
             route.RelayerRequiresAuth = true;
             route.RelayerAuthUsername = "******";
             route.SetRelayerAuthPassword("MySecretPassword");

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

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

             Utilities.AssertRecipientsInDeliveryQueue(0);

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

             Assert.IsFalse(messageText.Contains("MySecretPassword"));
             Assert.IsTrue(messageText.Contains("<Password removed>"));
        }
コード例 #2
0
ファイル: IMAP.Search.cs プロジェクト: nberardi/hMailServer
        public void TestNestedOrSearch()
        {
            hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp();

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

              // Send a message to this account.
              SMTPClientSimulator oSMTP = new SMTPClientSimulator();
              oSMTP.Send("*****@*****.**", "*****@*****.**", "Search test", "This is a test of IMAP Search");

              IMAPSimulator.AssertMessageCount(oAccount.Address, "test", "Inbox", 1);

              IMAPSimulator oSimulator = new IMAPSimulator();
              string sWelcomeMessage = oSimulator.Connect();
              oSimulator.Logon("*****@*****.**", "test");
              oSimulator.SelectFolder("INBOX");

              string result = oSimulator.SendSingleCommand("A4 SEARCH ALL OR OR SINCE 28-May-2008 SINCE 28-May-2008 SINCE 28-May-2008");
              Assert.IsTrue(result.StartsWith("* SEARCH 1"), result);

              result = oSimulator.SendSingleCommand("A4 SEARCH ALL OR SMALLER 1 LARGER 10000");
              Assert.IsTrue(result.StartsWith("* SEARCH\r\n"), result);

              result = oSimulator.SendSingleCommand("A4 SEARCH ALL OR OR SMALLER 1 LARGER 10000 SMALLER 10000");
              Assert.IsTrue(result.StartsWith("* SEARCH 1\r\n"), result);
        }
コード例 #3
0
        public void TestDomainAliases()
        {
            // Create a test account
             // Fetch the default domain
             hMailServer.DomainAlias oDomainAlias = _domain.DomainAliases.Add();
             oDomainAlias.AliasName = "alias.com";
             oDomainAlias.Save();

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

             // Send 5 messages to this account.
             SMTPClientSimulator oSMTP = new SMTPClientSimulator();
             for (int i = 0; i < 5; i++)
            oSMTP.Send("*****@*****.**", "*****@*****.**", "INBOX", "Alias test message");

             POP3Simulator.AssertMessageCount("*****@*****.**", "test", 5);

             {
            oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Set up an alias pointing at the domain alias.
            SingletonProvider<Utilities>.Instance.AddAlias(_domain, "*****@*****.**", "*****@*****.**");

            // Send to the alias
            for (int i = 0; i < 5; i++)
               oSMTP.Send(oAccount.Address, "*****@*****.**", "INBOX", "Plus addressing message");
            // Wait for completion

            POP3Simulator.AssertMessageCount(oAccount.Address, "test", 5);
             }
        }
コード例 #4
0
        public void ConfirmSingleReturnPathAfterAccountForward()
        {
            // Create a test account
            // Fetch the default domain
            hMailServer.Account oAccount1 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");
            hMailServer.Account oAccount2 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

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

            // Send a message...
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();
            oSMTP.Send("*****@*****.**", oAccount1.Address, "Test message", "This is the body");

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

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

            Assert.IsFalse(text.Contains("Return-Path: [email protected]"));
            Assert.IsFalse(text.Contains("Return-Path: [email protected]"));
            Assert.IsTrue(text.Contains("Return-Path: [email protected]"));
        }
コード例 #5
0
        public void TestBlockingDeliveries()
        {
            hMailServer.SecurityRange range = SingletonProvider<Utilities>.Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer");
            range.RequireSMTPAuthLocalToLocal = false;
            range.RequireSMTPAuthLocalToExternal = false;
            range.RequireSMTPAuthExternalToLocal = false;
            range.RequireSMTPAuthExternalToExternal = false;

            range.AllowDeliveryFromLocalToLocal = false;
            range.AllowDeliveryFromLocalToRemote = false;
            range.AllowDeliveryFromRemoteToLocal = false;
            range.AllowDeliveryFromRemoteToRemote = false;

            range.Save();

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

            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            string result1, result2, result3, result4;

            Assert.IsFalse(oSMTP.Send(account1.Address, account1.Address, "Mail 1", "Mail 1", out result1));
            Assert.IsFalse(oSMTP.Send(account1.Address, "*****@*****.**", "Mail 1", "Mail 1", out result2));
            Assert.IsFalse(oSMTP.Send("*****@*****.**", account1.Address, "Mail 1", "Mail 1", out result3));
            Assert.IsFalse(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result4));

            Assert.IsTrue(result1.Contains("550 Delivery is not allowed to this address."));
            Assert.IsTrue(result2.Contains("550 Delivery is not allowed to this address."));
            Assert.IsTrue(result3.Contains("550 Delivery is not allowed to this address."));
            Assert.IsTrue(result4.Contains("550 Delivery is not allowed to this address."));
        }
コード例 #6
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]"));
            }
        }
コード例 #7
0
ファイル: Basics.cs プロジェクト: shaqman/hmailserver
        public void TestSendToPostmasterAddress()
        {
            _domain.Postmaster = "*****@*****.**";
            _domain.Save();

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

            CustomAssert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Test", "Test"));
            POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1);
        }
コード例 #8
0
ファイル: Persistence.cs プロジェクト: nberardi/hMailServer
        public void TestCaseInsensitivtyAccount()
        {
            hMailServer.Account testAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             SMTPClientSimulator oSMTP = new SMTPClientSimulator();
             string upperCase = testAccount.Address.ToUpper();
             Assert.IsTrue(oSMTP.Send("*****@*****.**", upperCase, "test mail", "test body"));

             POP3Simulator.AssertMessageCount("*****@*****.**", "test", 1);
        }
コード例 #9
0
        public void TestSpamMultipleHits()
        {
            hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "mult'*****@*****.**", "test");

            _settings.AntiSpam.SpamMarkThreshold   = 1;
            _settings.AntiSpam.SpamDeleteThreshold = 2;

            _settings.AntiSpam.AddHeaderReason    = true;
            _settings.AntiSpam.AddHeaderSpam      = true;
            _settings.AntiSpam.PrependSubject     = true;
            _settings.AntiSpam.PrependSubjectText = "ThisIsSpam";

            // Enable SpamAssassin
            _settings.AntiSpam.SpamAssassinEnabled    = true;
            _settings.AntiSpam.SpamAssassinHost       = "localhost";
            _settings.AntiSpam.SpamAssassinPort       = 783;
            _settings.AntiSpam.SpamAssassinMergeScore = false;
            _settings.AntiSpam.SpamAssassinScore      = 5;


            // Enable SURBL.
            hMailServer.SURBLServer oSURBLServer = _settings.AntiSpam.SURBLServers[0];
            oSURBLServer.Active = true;
            oSURBLServer.Score  = 5;
            oSURBLServer.Save();

            // Send a messages to this account, containing both incorrect MX records an SURBL-hits.
            // We should only detect one of these two:
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            _settings.Logging.LogSMTP  = true;
            _settings.Logging.LogDebug = true;
            _settings.Logging.Enabled  = true;
            _settings.Logging.EnableLiveLogging(true);

            // Access the log once to make sure it's cleared.
            string liveLog = _settings.Logging.LiveLog;

            // Should not be possible to send this email since it's results in a spam
            // score over the delete threshold.
            Assert.IsFalse(oSMTP.Send("test@domain_without_mx_records421dfsam430sasd.com", oAccount1.Address, "INBOX", "This is a test message. It contains incorrect MX records and a SURBL string: http://surbl-org-permanent-test-point.com/ SpamAssassinString: XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"));

            liveLog = _settings.Logging.LiveLog;

            _settings.Logging.EnableLiveLogging(false);

            int iFirst = liveLog.IndexOf("Running spam test");
            int iLast  = liveLog.LastIndexOf("Running spam test");

            Assert.AreNotSame(-1, iFirst);

            // there should only be one spam test, since any spam match
            // should result in a spam score over the delete threshold.
            Assert.AreEqual(iFirst, iLast);
        }
コード例 #10
0
        public void TestPlusAddressing()
        {
            // Create a test account
            // Fetch the default domain
            // Enable plus adressing
            _domain.PlusAddressingEnabled   = true;
            _domain.PlusAddressingCharacter = "+";

            // Save the change
            _domain.Save();

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

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

            // Send 5 messages to this account, without using plus addressing.
            var oSMTP = new SMTPClientSimulator();

            for (int i = 0; i < 5; i++)
            {
                oSMTP.Send("*****@*****.**", "*****@*****.**", "INBOX", "Plus addressing message");
            }
            // Wait for completion

            // Check using POP3 that 5 messages exists.
            POP3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 5);

            // Send using plus addressing
            for (int i = 0; i < 5; i++)
            {
                oSMTP.Send("*****@*****.**", "*****@*****.**", "INBOX", "Plus addressing message");
            }
            // Wait for completion

            POP3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 10);

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

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

                // Send to the alias
                for (int i = 0; i < 5; i++)
                {
                    oSMTP.Send("*****@*****.**", "*****@*****.**", "INBOX", "Plus addressing message");
                }
                // Wait for completion

                POP3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 5);
            }

            _domain.PlusAddressingEnabled = false;
        }
コード例 #11
0
        public void TestIncorrectPort()
        {
            _antiVirus.ClamAVEnabled = true;
            _antiVirus.ClamAVPort    = 110;

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

            CustomAssert.IsTrue(SMTPClientSimulator.StaticSend(account1.Address, account1.Address, "Mail 1", "DummyBody"));
            POP3ClientSimulator.AssertMessageCount(account1.Address, "test", 1);
            TestSetup.AssertReportedError("Protocol error. Unexpected response: +OK");
        }
コード例 #12
0
ファイル: Basics.cs プロジェクト: shaqman/hmailserver
        public void TestPostmasterRecipientExternal()
        {
            _domain.Postmaster = "*****@*****.**";
            _domain.Save();

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

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

            CustomAssert.IsFalse(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Test", "Test"));
        }
コード例 #13
0
        public void TestUnusedPort()
        {
            _antiVirus.ClamAVEnabled = true;
            _antiVirus.ClamAVPort    = 54391;

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

            CustomAssert.IsTrue(SMTPClientSimulator.StaticSend(account1.Address, account1.Address, "Mail 1", "DummyBody"));
            POP3ClientSimulator.AssertMessageCount(account1.Address, "test", 1);
            TestSetup.AssertReportedError("Unable to connect to ClamAV server at localhost:54391.");
        }
コード例 #14
0
        public void TestNotEnabled()
        {
            TestSetup.DeleteCurrentDefaultLog();
            Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            CustomAssert.IsTrue(SMTPClientSimulator.StaticSend(account1.Address, account1.Address, "Mail 1", "Mail 1"));
            POP3ClientSimulator.AssertMessageCount(account1.Address, "test", 1);
            string defaultLog = TestSetup.ReadCurrentDefaultLog();

            CustomAssert.IsFalse(defaultLog.Contains("Connecting to ClamAV"));
        }
コード例 #15
0
ファイル: AccountServices.cs プロジェクト: radtek/hMailServer
        public void TestForwardingCombinedWithAccountRule()
        {
            // Create a test account
            // Fetch the default domain
            hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, Utilities.RandomString() + "@test.com", "test");

            hMailServer.Account oAccount2 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, Utilities.RandomString() + "@test.com", "test");

            hMailServer.Account oAccount3 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, Utilities.RandomString() + "@test.com", "test");

            oAccount2.ForwardAddress      = oAccount3.Address;
            oAccount2.ForwardEnabled      = true;
            oAccount2.ForwardKeepOriginal = true;
            oAccount2.Save();

            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            Assert.IsTrue(oSMTP.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body"));

            // Make sure that that a forward is made if no rule is set up.
            POP3Simulator.AssertMessageCount(oAccount2.Address, "test", 1);
            _application.SubmitEMail();
            POP3Simulator.AssertMessageCount(oAccount3.Address, "test", 1);

            // Start over again.
            oAccount2.DeleteMessages();
            oAccount3.DeleteMessages();

            // Set up a rule to trash the message.
            hMailServer.Rule oRule = oAccount2.Rules.Add();
            oRule.Name   = "Criteria test";
            oRule.Active = true;

            hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add();
            oRuleCriteria.UsePredefined   = true;
            oRuleCriteria.PredefinedField = hMailServer.eRulePredefinedField.eFTMessageSize;
            oRuleCriteria.MatchType       = hMailServer.eRuleMatchType.eMTGreaterThan;
            oRuleCriteria.MatchValue      = "0";
            oRuleCriteria.Save();

            // Add action
            hMailServer.RuleAction oRuleAction = oRule.Actions.Add();
            oRuleAction.Type = hMailServer.eRuleActionType.eRADeleteEmail;
            oRuleAction.Save();

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

            // Make sure that that a forward is made if no rule is set up.
            Assert.IsTrue(oSMTP.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body"));
            POP3Simulator.AssertMessageCount(oAccount2.Address, "test", 0);
            _application.SubmitEMail();
            POP3Simulator.AssertMessageCount(oAccount3.Address, "test", 0);
        }
コード例 #16
0
ファイル: SMTPClientTests.cs プロジェクト: radtek/hMailServer
        public void TestDeliverToMyselfOnLocalPortAfterChangedLocalPort()
        {
            hMailServer.TCPIPPorts oPorts = _application.Settings.TCPIPPorts;
            for (int i = 0; i < oPorts.Count; i++)
            {
                hMailServer.TCPIPPort oTestPort = oPorts[i];
                if (oTestPort.Protocol == hMailServer.eSessionType.eSTIMAP)
                {
                    oTestPort.PortNumber = 14300;
                }
                else if (oTestPort.Protocol == hMailServer.eSessionType.eSTSMTP)
                {
                    oTestPort.PortNumber = 11000;
                }
                else if (oTestPort.Protocol == hMailServer.eSessionType.eSTPOP3)
                {
                    oTestPort.PortNumber = 2500;
                }

                oTestPort.Save();
            }

            _application.Stop();
            _application.Start();

            // Set up a server and start listening.
            Dictionary <string, int> deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;
            SMTPServerSimulator server = new SMTPServerSimulator(1, 25);

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

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

            // Send message to this route.
            SMTPClientSimulator sim = new SMTPClientSimulator(false, 11000);

            sim.Send("*****@*****.**", "*****@*****.**", "Test", "Test message");


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

            Utilities.AssertRecipientsInDeliveryQueue(0, false);

            Assert.IsTrue(server.MessageData.Contains("Test message"));

            oPorts.SetDefault();
            _application.Stop();
            _application.Start();
        }
コード例 #17
0
        public void TestCaseInsensitivtyAccount()
        {
            Account testAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            var    oSMTP     = new SMTPClientSimulator();
            string upperCase = testAccount.Address.ToUpper();

            CustomAssert.IsTrue(oSMTP.Send("*****@*****.**", upperCase, "test mail", "test body"));

            POP3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 1);
        }
コード例 #18
0
        public void TestBasic()
        {
            // Send a messages to this account.
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            Assert.IsTrue(oSMTP.Send(account.Address, account.Address, "SA test", "This is a test message."));
            string sMessageContents = POP3Simulator.AssertGetFirstMessageText(account.Address, "test");
            if (!sMessageContents.Contains("X-Spam-Status"))
            {
                Assert.Fail("SpamAssassin did not run");
            }
        }
コード例 #19
0
        public void TestSURBL()
        {
            hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp();

            // Create a test account
            // Fetch the default domain
            ;
            hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Disallow incorrect line endings.
            _antiSpam.SpamMarkThreshold   = 1;
            _antiSpam.SpamDeleteThreshold = 100;
            _antiSpam.AddHeaderReason     = true;
            _antiSpam.AddHeaderSpam       = true;
            _antiSpam.PrependSubject      = true;
            _antiSpam.PrependSubjectText  = "ThisIsSpam";

            // Enable SURBL.
            hMailServer.SURBLServer oSURBLServer = _antiSpam.SURBLServers[0];
            oSURBLServer.Active = true;
            oSURBLServer.Score  = 5;
            oSURBLServer.Save();

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


            oSMTP.Send("*****@*****.**", "*****@*****.**", "SURBL-No-Match", "This is a test message without a SURBL url.");

            string sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test");

            if (sMessageContents.Length == 0 ||
                sMessageContents.Contains("X-hMailServer-Spam") ||
                sMessageContents.Contains("X-hMailServer-Reason") ||
                sMessageContents.Contains("ThisIsSpam"))
            {
                throw new Exception("Non-Spam message detected as spam");
            }


            oSMTP.Send("*****@*****.**", "*****@*****.**", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-");

            sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test");
            if (!sMessageContents.Contains("X-hMailServer-Spam") ||
                !sMessageContents.Contains("X-hMailServer-Reason") ||
                !sMessageContents.Contains("ThisIsSpam"))
            {
                throw new Exception("Spam message not detected as spam");
            }

            oSURBLServer.Active = false;
            oSURBLServer.Save();
        }
コード例 #20
0
        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."));
        }
コード例 #21
0
ファイル: Basics.cs プロジェクト: shaqman/hmailserver
        public void TestMaxSizeNoLimit()
        {
            Application application = SingletonProvider <TestSetup> .Instance.GetApp();

            // Create a test account
            // Fetch the default domain

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

            // Disallow incorrect line endings.
            _antiSpam.SpamMarkThreshold   = 1;
            _antiSpam.SpamDeleteThreshold = 100;
            _antiSpam.AddHeaderReason     = true;
            _antiSpam.AddHeaderSpam       = true;
            _antiSpam.PrependSubject      = true;
            _antiSpam.PrependSubjectText  = "ThisIsSpam";
            _antiSpam.MaximumMessageSize  = 0;

            // Enable SURBL.
            SURBLServer oSURBLServer = _antiSpam.SURBLServers[0];

            oSURBLServer.Active = true;
            oSURBLServer.Score  = 5;
            oSURBLServer.Save();

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

            var sb         = new StringBuilder();
            int iterations = ((40 * 1024) / 100) + 1;

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

            CustomAssert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "SURBL-No-Match",
                                           "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-\r\n" +
                                           sb));

            string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");

            if (!sMessageContents.Contains("X-hMailServer-Spam") ||
                !sMessageContents.Contains("X-hMailServer-Reason") ||
                !sMessageContents.Contains("ThisIsSpam"))
            {
                throw new Exception("Spam message not detected as spam.");
            }

            oSURBLServer.Active = false;
            oSURBLServer.Save();
        }
コード例 #22
0
        public void TestESMTPAInHeader()
        {
            string errorMessage;

            var client = new SMTPClientSimulator();

            client.Send(false, _account.Address, "test", _account.Address, _account.Address, "Test", "Test", out errorMessage);

            var message = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test");

            CustomAssert.IsTrue(message.Contains("ESMTPA\r\n"));
        }
コード例 #23
0
        public void TestESMTPSInHeader()
        {
            var smtpClientSimulator = new SMTPClientSimulator(false, 25002);

            string errorMessage;

            smtpClientSimulator.Send(true, string.Empty, string.Empty, _account.Address, _account.Address, "Test", "test", out errorMessage);

            var message = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test");

            CustomAssert.IsTrue(message.Contains("ESMTPS\r\n"));
        }
コード例 #24
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]"));
            }
        }
コード例 #25
0
        public void TestLongLineInData()
        {
            hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 11000; i++)
            {
                sb.Append("1234567890");
            }

            SMTPClientSimulator sim = new SMTPClientSimulator();
            Assert.IsFalse(sim.SendRaw("*****@*****.**", "*****@*****.**", sb.ToString()));
        }
コード例 #26
0
ファイル: Persistence.cs プロジェクト: radtek/hMailServer
        public void TestCaseInsensitivtyAlias()
        {
            hMailServer.Account testAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            hMailServer.Alias testAlias = SingletonProvider <Utilities> .Instance.AddAlias(_domain, "*****@*****.**", "*****@*****.**");

            SMTPClientSimulator oSMTP = new SMTPClientSimulator();
            string upperCase          = testAlias.Name.ToUpper();

            Assert.IsTrue(oSMTP.Send("*****@*****.**", upperCase, "test mail", "test body"));

            POP3Simulator.AssertMessageCount("*****@*****.**", "test", 1);
        }
コード例 #27
0
        public void TestChangeFlags()
        {
            Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            CustomAssert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", oAccount.Address, "Test", "test"));
            POP3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 1);

            var simulator = new IMAPClientSimulator();

            simulator.ConnectAndLogon(oAccount.Address, "test");
            simulator.ExamineFolder("Inbox");
            CustomAssert.IsFalse(simulator.SetFlagOnMessage(1, true, @"\Deleted"));
        }
コード例 #28
0
        public void TestBasic()
        {
            // Send a messages to this account.
            var oSMTP = new SMTPClientSimulator();

            CustomAssert.IsTrue(oSMTP.Send(account.Address, account.Address, "SA test", "This is a test message."));
            string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test");

            if (!sMessageContents.Contains("X-Spam-Status"))
            {
                CustomAssert.Fail("SpamAssassin did not run");
            }
        }
コード例 #29
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"));
            }
        }
コード例 #30
0
ファイル: AccountServices.cs プロジェクト: radtek/hMailServer
        public void TestAutoReply()
        {
            // Create a test account
            // Fetch the default domain
            hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, Utilities.RandomString() + "@test.com", "test");

            hMailServer.Account oAccount2 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, Utilities.RandomString() + "@test.com", "test");

            oAccount2.VacationMessageIsOn = true;
            oAccount2.VacationMessage     = "I'm on vacation";
            oAccount2.VacationSubject     = "Out of office!";
            oAccount2.Save();

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

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

            POP3Simulator oPOP3 = new POP3Simulator();

            POP3Simulator.AssertMessageCount(oAccount1.Address, "test", 1);
            POP3Simulator.AssertMessageCount(oAccount2.Address, "test", 1);
            string s = oPOP3.GetFirstMessageText(oAccount1.Address, "test");

            if (s.IndexOf("Out of office!") < 0)
            {
                throw new Exception("ERROR - Auto reply subject not set properly.");
            }

            oAccount2.VacationMessageIsOn = false;
            oAccount2.Save();

            oAccount2.VacationSubject     = "";
            oAccount2.VacationMessageIsOn = true;
            oAccount2.Save();

            // Send another
            oSMTP.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body");

            POP3Simulator.AssertMessageCount(oAccount2.Address, "test", 2);
            POP3Simulator.AssertMessageCount(oAccount1.Address, "test", 1);

            s = oPOP3.GetFirstMessageText(oAccount1.Address, "test");
            if (s.ToLower().IndexOf("re: test message") < 0)
            {
                throw new Exception("ERROR - Auto reply subject not set properly.");
            }

            oAccount2.VacationMessageIsOn = false;
            oAccount2.Save();
        }
コード例 #31
0
        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."));
        }
コード例 #32
0
        public void TestSANotRunning()
        {
            TestSetup.StopSpamAssassin();

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

            CustomAssert.IsTrue(oSMTP.Send(account.Address, account.Address, "SA test", "This is a test message."));
            string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test");

            CustomAssert.IsFalse(sMessageContents.Contains("X-Spam-Status"));

            TestSetup.AssertReportedError();
        }
コード例 #33
0
        public void ItShouldBePossibleToBypassGreylistingOnMessagesArrivingFromMXorA()
        {
            hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            _antiSpam.GreyListingEnabled = true;

            Assert.IsFalse(SMTPClientSimulator.StaticSend("*****@*****.**", oAccount1.Address, "Test", "Body"));

            _antiSpam.BypassGreylistingOnMailFromMX = true;

            Assert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", oAccount1.Address, "Test", "Body"));

            POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test");
        }
コード例 #34
0
ファイル: AntiVirus.cs プロジェクト: radtek/hMailServer
        public void TestAttachmentRemoval()
        {
            SingletonProvider <Utilities> .Instance.GetApp().Settings.AntiVirus.EnableAttachmentBlocking = true;

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

            // Send a message to the account.
            string messageText = @"Date: Thu, 03 Jul 2008 22:01:53 +0200\r\n" +
                                 "From: Test <*****@*****.**>\r\n" +
                                 "MIME-Version: 1.0\r\n" +
                                 "To: [email protected]\r\n" +
                                 "Subject: test\r\n" +
                                 "Content-Type: multipart/mixed;\r\n" +
                                 "  boundary=\"------------050908050500020808050006\"\r\n" +
                                 "\r\n" +
                                 "This is a multi-part message in MIME format.\r\n" +
                                 "--------------050908050500020808050006\r\n" +
                                 "Content-Type: text/plain; charset=ISO-8859-1; format=flowed\r\n" +
                                 "Content-Transfer-Encoding: 7bit\r\n" +
                                 "\r\n" +
                                 "Test\r\n" +
                                 "\r\n" +
                                 "--------------050908050500020808050006\r\n" +
                                 "Content-Type: text/plain;\r\n" +
                                 " name=\"AUTOEXEC.BAT\"\r\n" +
                                 "Content-Transfer-Encoding: base64\r\n" +
                                 "Content-Disposition: inline;\r\n" +
                                 " filename=\"AUTOEXEC.BAT\"\r\n" +
                                 "\r\n" +
                                 "\r\n" +
                                 "--------------050908050500020808050006--\r\n";

            SMTPClientSimulator.StaticSendRaw("*****@*****.**", "*****@*****.**", messageText);

            hMailServer.Message message = Utilities.AssertRetrieveFirstMessage(account1.IMAPFolders.get_ItemByName("INBOX"));
            Assert.AreEqual(1, message.Attachments.Count);
            Assert.AreEqual("AUTOEXEC.BAT.txt", message.Attachments[0].Filename);

            string tempFile = System.IO.Path.GetTempFileName();

            message.Attachments[0].SaveAs(tempFile);
            string contents = System.IO.File.ReadAllText(tempFile);

            string removedMessage = SingletonProvider <Utilities> .Instance.GetApp().Settings.ServerMessages.get_ItemByName("ATTACHMENT_REMOVED").Text;

            removedMessage = removedMessage.Replace("%MACRO_FILE%", message.Attachments[0].Filename.Substring(0, message.Attachments[0].Filename.Length - 4));

            Assert.IsTrue(contents.Contains(removedMessage));
            System.IO.File.Delete(tempFile);
        }
コード例 #35
0
        public void TestIpAddressAsHostName()
        {
            var smtpClientSimulator = new SMTPClientSimulator();

            _settings.AntiSpam.SpamAssassinEnabled = true;
            _settings.AntiSpam.SpamAssassinHost    = "127.0.0.1";
            smtpClientSimulator.Send(account.Address, account.Address, "SA test", "This is a test message.");
            string messageContents = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test");

            if (!messageContents.Contains("X-Spam-Status"))
            {
                CustomAssert.Fail("SpamAssassin did not run");
            }
        }
コード例 #36
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)"));
        }
コード例 #37
0
        public void TestOnAcceptMessageVBScript()
        {
            Application application = SingletonProvider <TestSetup> .Instance.GetApp();

            string eventLogFile = _settings.Logging.CurrentEventLog;

            if (File.Exists(eventLogFile))
            {
                File.Delete(eventLogFile);
            }

            // First set up a script
            string script =
                @"Sub OnAcceptMessage(oClient, oMessage)
                               oMessage.HeaderValue(""X-SpamResult"") = ""TEST""
                               oMessage.Save()
                               EventLog.Write(""Port: "" & oClient.Port)
                               EventLog.Write(""Address: "" & oClient.IPAddress)
                               EventLog.Write(""Username: "" & oClient.Username)
                              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, oAccount1.Address, "Test", "SampleBody");

            // Check that the message exists
            string message = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test");

            CustomAssert.IsNotEmpty(message);

            CustomAssert.Less(0, message.IndexOf("X-SpamResult: TEST"));


            // Check that the message exists
            message = TestSetup.ReadExistingTextFile(eventLogFile);

            CustomAssert.IsNotEmpty(message);
            CustomAssert.IsTrue(message.Contains("Port: 25"));
            CustomAssert.IsTrue(message.Contains("Address: 127"));
            CustomAssert.IsTrue(message.Contains("Username: \"")); // Should be empty, Username isn't available at this time.
        }
コード例 #38
0
        public void TestSaveMessageWithScriptAndMoveMessageWithGlobalRule()
        {
            _settings.Scripting.Enabled = true;

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

            var sim = new IMAPClientSimulator();

            CustomAssert.IsTrue(sim.ConnectAndLogon(testAccount.Address, "test"));

            // First deliver two messages to the inbox.
            SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test");
            POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1);
            IMAPFolder inboxFolder = testAccount.IMAPFolders[0];

            CustomAssert.AreEqual(1, inboxFolder.CurrentUID);
            CustomAssert.AreEqual(1, inboxFolder.Messages[0].UID);
            CustomAssert.IsTrue(sim.Status("INBOX", "UIDNEXT").Contains("UIDNEXT 2"));

            SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test");
            POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 2);
            CustomAssert.AreEqual(2, inboxFolder.CurrentUID);
            CustomAssert.AreEqual(2, inboxFolder.Messages[1].UID);
            CustomAssert.IsTrue(sim.Status("INBOX", "UIDNEXT").Contains("UIDNEXT 3"));

            CreateMessageModificationRule(_application.Rules);
            CreateMoveRule(_application.Rules, "TestFolder");


            // This message will be moved into the test folder.
            SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test");

            // Wait for the message to arrive.
            TestSetup.AssertFolderExists(testAccount.IMAPFolders, "TestFolder");
            IMAPFolder testFolder = testAccount.IMAPFolders.get_ItemByName("TestFolder");

            TestSetup.AssertFolderMessageCount(testFolder, 1);

            // Inbox UID should not have changed since nothing has been added to the inbox.
            CustomAssert.IsTrue(sim.Status("INBOX", "UIDNEXT").Contains("UIDNEXT 3"));

            // Since the message is placed in a new folder, it should receive a unique UID.
            string status = sim.Status("TestFolder", "UIDNEXT");

            CustomAssert.IsTrue(status.Contains("UIDNEXT 2"), status);
            CustomAssert.AreEqual(1, testFolder.CurrentUID);
            CustomAssert.AreEqual(1, testFolder.Messages[0].UID);
        }
コード例 #39
0
        public void TestDisabled()
        {
            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            _settings.AntiSpam.SpamAssassinEnabled = false;
            _settings.AntiSpam.SpamAssassinHost = "localhost";
            oSMTP.Send(account.Address, account.Address, "SA test", "This is a test message.");

            string sMessageContents = POP3Simulator.AssertGetFirstMessageText(account.Address, "test");
            if (sMessageContents.Contains("X-Spam-Status"))
            {
                _settings.AntiSpam.SpamAssassinEnabled = false;
                throw new Exception("Spam assassin not run");
            }
        }
コード例 #40
0
        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));
        }
コード例 #41
0
ファイル: Rules.cs プロジェクト: nberardi/hMailServer
        public void ActionAccountRuleMoveToExistingPublicFolder()
        {
            hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp();

             // Add an account
             hMailServer.Account account1 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             hMailServer.IMAPFolders publicFolders = _settings.PublicFolders;
             hMailServer.IMAPFolder folder = publicFolders.Add("Share1");
             folder.Save();

             hMailServer.IMAPFolderPermission permission = folder.Permissions.Add();
             permission.PermissionAccountID = account1.ID;
             permission.PermissionType = hMailServer.eACLPermissionType.ePermissionTypeUser;
             permission.set_Permission(hMailServer.eACLPermission.ePermissionInsert, true);
             permission.set_Permission(hMailServer.eACLPermission.ePermissionRead, true);
             permission.set_Permission(hMailServer.eACLPermission.ePermissionExpunge, true);
             permission.Save();

             hMailServer.Rule oRule = account1.Rules.Add();
             oRule.Name = "Criteria test";
             oRule.Active = true;

             hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add();
             oRuleCriteria.UsePredefined = true;
             oRuleCriteria.PredefinedField = hMailServer.eRulePredefinedField.eFTMessageSize;
             oRuleCriteria.MatchType = hMailServer.eRuleMatchType.eMTGreaterThan;
             oRuleCriteria.MatchValue = "0";
             oRuleCriteria.Save();

             // Add action
             hMailServer.RuleAction oRuleAction = oRule.Actions.Add();
             oRuleAction.Type = hMailServer.eRuleActionType.eRAMoveToImapFolder;
             oRuleAction.IMAPFolder = "#public.Share1";
             oRuleAction.Save();

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

             SMTPClientSimulator oSMTP = new SMTPClientSimulator();

             // Spam folder
             Assert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "SomeString", "Detta ska hamna i public folder."));

             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "#public.Share1", 1);
        }
コード例 #42
0
        public void TestMultipleDomains()
        {
            hMailServer.Domains domains = SingletonProvider<Utilities>.Instance.GetApp().Domains;

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

             hMailServer.Domain domain2 = SingletonProvider<Utilities>.Instance.AddDomain(domains, "test2.com");

             hMailServer.Account account3 = SingletonProvider<Utilities>.Instance.AddAccount(domain2, "*****@*****.**", "test");
             hMailServer.Account account4 = SingletonProvider<Utilities>.Instance.AddAccount(domain2, "*****@*****.**", "test");

             SMTPClientSimulator smtpSimulator = new SMTPClientSimulator();
             smtpSimulator.Send("*****@*****.**", account1.Address, "Test", "*****@*****.**");
             smtpSimulator.Send("*****@*****.**", account2.Address, "Test", "*****@*****.**");
             smtpSimulator.Send("*****@*****.**", account3.Address, "Test", "*****@*****.**");
             smtpSimulator.Send("*****@*****.**", account4.Address, "Test", "*****@*****.**");

             Assert.IsTrue(POP3Simulator.AssertGetFirstMessageText(account1.Address, "test").Contains(account1.Address));
             Assert.IsTrue(POP3Simulator.AssertGetFirstMessageText(account2.Address, "test").Contains(account2.Address));
             Assert.IsTrue(POP3Simulator.AssertGetFirstMessageText(account3.Address, "test").Contains(account3.Address));
             Assert.IsTrue(POP3Simulator.AssertGetFirstMessageText(account4.Address, "test").Contains(account4.Address));
        }
コード例 #43
0
        public void TestDeleteThresholdLowerThanMarkThreshold()
        {
            hMailServer.Account oAccount1 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             hMailServer.AntiSpam antiSpam = _settings.AntiSpam;

             antiSpam.SpamMarkThreshold = 15;
             antiSpam.SpamDeleteThreshold = 0;

             antiSpam.AddHeaderReason = true;
             antiSpam.AddHeaderSpam = true;
             antiSpam.PrependSubject = true;
             antiSpam.PrependSubjectText = "ThisIsSpam";

             antiSpam.CheckHostInHelo = true;
             antiSpam.CheckHostInHeloScore = 10;

             // Enable SURBL.
             hMailServer.SURBLServer oSURBLServer = antiSpam.SURBLServers[0];
             oSURBLServer.Active = true;
             oSURBLServer.Score = 10;
             oSURBLServer.Save();

             // Send a messages to this account, containing both incorrect MX records an SURBL-hits.
             // We should only detect one of these two:
             SMTPClientSimulator oSMTP = new SMTPClientSimulator();

             // Should not be possible to send this email since it's results in a spam
             // score over the delete threshold.
             Assert.IsTrue(oSMTP.Send("*****@*****.**", oAccount1.Address, "INBOX", "Test http://surbl-org-permanent-test-point.com/ Test 2"));

             string message = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test");

             Assert.IsTrue(message.Contains("X-hMailServer-Reason-1:"));
             Assert.IsTrue(message.Contains("X-hMailServer-Reason-2:"));
        }
コード例 #44
0
        public void TestGreyListing()
        {
            _antiSpam.GreyListingEnabled = false;

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

             SMTPClientSimulator smtp = new SMTPClientSimulator();
             List<string> recipients = new List<string>();
             recipients.Add(oAccount1.Address);
             bool result = smtp.Send("*****@*****.**", recipients, "Test", "Body");
             Assert.IsTrue(result);
             POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test");

             _antiSpam.GreyListingEnabled = true;

             result = smtp.Send("*****@*****.**", recipients, "Test", "Body");
             Assert.IsFalse(result);

             _antiSpam.GreyListingEnabled = false;

             result = smtp.Send("*****@*****.**", recipients, "Test", "Body");
             Assert.IsTrue(result);
             POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test");
        }
コード例 #45
0
ファイル: Rules.cs プロジェクト: nberardi/hMailServer
        public void ActionDelete()
        {
            // Add an account
             hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             hMailServer.Rule oRule = oAccount.Rules.Add();
             oRule.Name = "Criteria test";
             oRule.Active = true;

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

             // Add action
             hMailServer.RuleAction oRuleAction = oRule.Actions.Add();
             oRuleAction.Type = hMailServer.eRuleActionType.eRADeleteEmail;
             oRuleAction.Save();

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

             SMTPClientSimulator oSMTP = new SMTPClientSimulator();

             // Spam folder
             oSMTP.Send("*****@*****.**", "*****@*****.**", "TestString", "Test 1");
             oSMTP.Send("*****@*****.**", "*****@*****.**", "a", "Test 2");
             oSMTP.Send("*****@*****.**", "*****@*****.**", "TestString", "Test 3");
             oSMTP.Send("*****@*****.**", "*****@*****.**", "b", "Test 2");

             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 2);

             int fileCount = 0;
             string domainDir = Path.Combine(_application.Settings.Directories.DataDirectory, "test.com");
             string userDir = Path.Combine(domainDir, "ruletest");

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

             Assert.AreEqual(2, fileCount);
        }
コード例 #46
0
ファイル: Rules.cs プロジェクト: nberardi/hMailServer
        public void CriteriaWildcardPartialMatch()
        {
            // Add an account
             hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             hMailServer.Rule oRule = oAccount.Rules.Add();
             oRule.Name = "Criteria test";
             oRule.Active = true;

             hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add();
             oRuleCriteria.UsePredefined = false;
             oRuleCriteria.HeaderField = "Subject";
             oRuleCriteria.MatchType = hMailServer.eRuleMatchType.eMTWildcard;
             oRuleCriteria.MatchValue = "Exact*Match";
             oRuleCriteria.Save();

             // Add action
             hMailServer.RuleAction oRuleAction = oRule.Actions.Add();
             oRuleAction.Type = hMailServer.eRuleActionType.eRAMoveToImapFolder;
             oRuleAction.IMAPFolder = "INBOX.Wildcard";
             oRuleAction.Save();

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

             SMTPClientSimulator oSMTP = new SMTPClientSimulator();

             // Spam folder
             oSMTP.Send("*****@*****.**", "*****@*****.**", "Exact Test Match", "Detta ska hamna i mappen Inbox\\Wildcard");
             oSMTP.Send("*****@*****.**", "*****@*****.**", "ExactMatchArInte", "Detta ska inte hamna Inbox\\Wildcard");

             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox.Wildcard", 1);
             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1);
        }
コード例 #47
0
ファイル: Rules.cs プロジェクト: nberardi/hMailServer
        public void CriteriaRegEx()
        {
            // Add an account
             hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             hMailServer.Rule oRule = oAccount.Rules.Add();
             oRule.Name = "Criteria test";
             oRule.Active = true;

             hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add();
             oRuleCriteria.UsePredefined = false;
             oRuleCriteria.HeaderField = "Subject";
             oRuleCriteria.MatchType = hMailServer.eRuleMatchType.eMTRegExMatch;
             oRuleCriteria.MatchValue = "[a-f]*";
             oRuleCriteria.Save();

             // Add action
             hMailServer.RuleAction oRuleAction = oRule.Actions.Add();
             oRuleAction.Type = hMailServer.eRuleActionType.eRAMoveToImapFolder;
             oRuleAction.IMAPFolder = "INBOX.RegEx";
             oRuleAction.Save();

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

             SMTPClientSimulator oSMTP = new SMTPClientSimulator();

             // Spam folder
             oSMTP.Send("*****@*****.**", "*****@*****.**", "abc", "Detta ska hamna i mappen Inbox\\Wildcard");
             oSMTP.Send("*****@*****.**", "*****@*****.**", "abcdef", "Detta ska hamna i mappen Inbox\\Wildcard");
             oSMTP.Send("*****@*****.**", "*****@*****.**", "abcdefghi", "Detta ska inte hamna i mappen Inbox\\Wildcard");

             Utilities.AssertRecipientsInDeliveryQueue(0);

             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox.RegEx", 2);
             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1);
        }
コード例 #48
0
ファイル: TCPIP.cs プロジェクト: nberardi/hMailServer
        public void TestPortOpening()
        {
            hMailServer.Application oApp = SingletonProvider<Utilities>.Instance.GetApp();

             oApp.Settings.TCPIPPorts.SetDefault();

             SMTPClientSimulator pSMTPSimulator = new SMTPClientSimulator();
             POP3Simulator pPOP3Simulator = new POP3Simulator();
             IMAPSimulator pIMAPSimulator = new IMAPSimulator();

             oApp.Stop();

             hMailServer.TCPIPPorts oPorts = oApp.Settings.TCPIPPorts;
             for (int i = 0; i < oPorts.Count; i++)
             {
            hMailServer.TCPIPPort oTestPort = oPorts[i];
            if (oTestPort.Protocol == hMailServer.eSessionType.eSTIMAP)
               oTestPort.PortNumber = 14300;
            else if (oTestPort.Protocol == hMailServer.eSessionType.eSTSMTP)
               oTestPort.PortNumber = 11000;
            else if (oTestPort.Protocol == hMailServer.eSessionType.eSTPOP3)
               oTestPort.PortNumber = 2500;

            oTestPort.Save();
             }

             oApp.Start();

             Assert.IsTrue(pSMTPSimulator.TestConnect(2500));
             Assert.IsTrue(pSMTPSimulator.TestConnect(11000));
             Assert.IsTrue(pSMTPSimulator.TestConnect(14300));

             oApp.Stop();

             hMailServer.TCPIPPort oPort = oApp.Settings.TCPIPPorts.Add();
             oPort.Protocol = hMailServer.eSessionType.eSTSMTP;
             oPort.PortNumber = 25000;
             oPort.Save();

             oApp.Start();

             // Try to connect to the new port
             Assert.IsTrue(pSMTPSimulator.TestConnect(25000));

             oApp.Stop();

              // Delete the port again
             oApp.Settings.TCPIPPorts.DeleteByDBID(oPort.ID);

             // Change back the ports
             for (int i = 0; i < oPorts.Count; i++)
             {
            hMailServer.TCPIPPort oTestPort = oPorts[i];
            if (oTestPort.Protocol == hMailServer.eSessionType.eSTIMAP)
               oTestPort.PortNumber = 143;
            else if (oTestPort.Protocol == hMailServer.eSessionType.eSTSMTP)
               oTestPort.PortNumber = 25;
            else if (oTestPort.Protocol == hMailServer.eSessionType.eSTPOP3)
               oTestPort.PortNumber = 110;

            oTestPort.Save();
             }

             oApp.Start();

             Assert.IsTrue(pSMTPSimulator.TestConnect(25));
             Assert.IsTrue(pPOP3Simulator.TestConnect(110));
             Assert.IsTrue(pPOP3Simulator.TestConnect(143));
        }
コード例 #49
0
 public void TestSMTPServerAuthLogin()
 {
     SMTPClientSimulator sim = new SMTPClientSimulator();
     string errorMsg;
     sim.ConnectAndLogon(25, GetUsername(), GetPassword(), out errorMsg);
     EnsureNoPassword();
 }
コード例 #50
0
ファイル: Rules.cs プロジェクト: nberardi/hMailServer
        public void ActionOverrideMoveToIMAPFolder()
        {
            // Add an account
             hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             hMailServer.Rule oRule = SingletonProvider<Utilities>.Instance.GetApp().Rules.Add();
             oRule.Name = "Global rule test";
             oRule.Active = true;
             hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add();
             oRuleCriteria.UsePredefined = false;
             oRuleCriteria.HeaderField = "Subject";
             oRuleCriteria.MatchType = hMailServer.eRuleMatchType.eMTNotEquals;
             oRuleCriteria.MatchValue = "SomeString";
             oRuleCriteria.Save();
             // Add action
             hMailServer.RuleAction oRuleAction = oRule.Actions.Add();
             oRuleAction.Type = hMailServer.eRuleActionType.eRAMoveToImapFolder;
             oRuleAction.IMAPFolder = "INBOX.GlobalBox";
             oRuleAction.Save();
             oRule.Save();

             // Account-level rule
             hMailServer.Rule oAccountRule = oAccount.Rules.Add();
             oAccountRule.Name = "Criteria test";
             oAccountRule.Active = true;

             oRuleCriteria = oAccountRule.Criterias.Add();
             oRuleCriteria.UsePredefined = false;
             oRuleCriteria.HeaderField = "Subject";
             oRuleCriteria.MatchType = hMailServer.eRuleMatchType.eMTNotEquals;
             oRuleCriteria.MatchValue = "SomeString";
             oRuleCriteria.Save();

             // Add action
             oRuleAction = oAccountRule.Actions.Add();
             oRuleAction.Type = hMailServer.eRuleActionType.eRAMoveToImapFolder;
             oRuleAction.IMAPFolder = "INBOX.Overriden.Test";
             oRuleAction.Save();

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

             SMTPClientSimulator oSMTP = new SMTPClientSimulator();

             // Spam folder
             oSMTP.Send("*****@*****.**", "*****@*****.**", "SomeString", "Detta ska inte hamna i mappen Inbox.Overriden.Test");
             oSMTP.Send("*****@*****.**", "*****@*****.**", "SomeStringA", "Detta ska hamna i mappen Inbox.Overriden.Test");
             oSMTP.Send("*****@*****.**", "*****@*****.**", "somestring", "Detta ska inte hamna i mappen Inbox.Overriden.Test");

             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox.Overriden.Test", 1);
             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 2);
        }
コード例 #51
0
ファイル: Rules.cs プロジェクト: nberardi/hMailServer
        public void ActionSetHeaderContents()
        {
            // Add an account
             hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             hMailServer.Rule oRule = oAccount.Rules.Add();
             oRule.Name = "Criteria test";
             oRule.Active = true;

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

             // Add action
             hMailServer.RuleAction oRuleAction = oRule.Actions.Add();
             oRuleAction.Type = hMailServer.eRuleActionType.eRASetHeaderValue;
             oRuleAction.HeaderName = "SomeHeader";
             oRuleAction.Value = "SomeValue";
             oRuleAction.Save();

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

             SMTPClientSimulator oSMTP = new SMTPClientSimulator();

             // Spam folder
             oSMTP.Send("*****@*****.**", "*****@*****.**", "TestString", "Test 1");

             string sContents = POP3Simulator.AssertGetFirstMessageText("*****@*****.**", "test");

             if (sContents.IndexOf("SomeHeader: SomeValue") <= 0)
            throw new Exception("Message header not set");
        }
コード例 #52
0
ファイル: Rules.cs プロジェクト: nberardi/hMailServer
        public void CriteriaContains()
        {
            Stopwatch watch = new Stopwatch();
             watch.Start();

             // Add an account
             hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             hMailServer.Rule oRule = oAccount.Rules.Add();
             oRule.Name = "Criteria test";
             oRule.Active = true;

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

             // Add action
             hMailServer.RuleAction oRuleAction = oRule.Actions.Add();
             oRuleAction.Type = hMailServer.eRuleActionType.eRAMoveToImapFolder;
             oRuleAction.IMAPFolder = "INBOX.Wildcard";
             oRuleAction.Save();

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

             SMTPClientSimulator oSMTP = new SMTPClientSimulator();

             // Spam folder
             oSMTP.Send("*****@*****.**", "*****@*****.**", "TestString", "Detta ska hamna i mappen Inbox\\Wildcard");
             oSMTP.Send("*****@*****.**", "*****@*****.**", "TestStri", "Detta ska inte hamna Inbox\\Wildcard");
             oSMTP.Send("*****@*****.**", "*****@*****.**", "VaffeTestStringBaffe", "Detta ska hamna i mappen Inbox\\Wildcard");

             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox.Wildcard", 2);
             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1);

             Trace.WriteLine(watch.ElapsedMilliseconds);
        }
コード例 #53
0
        public void TestHelo()
        {
            hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp();

             hMailServer.WhiteListAddresses obAddresses = _antiSpam.WhiteListAddresses;
             hMailServer.WhiteListAddress obAddress = obAddresses.Add();

             obAddress.EmailAddress = "*****@*****.**";
             obAddress.LowerIPAddress = "0.0.0.0";
             obAddress.UpperIPAddress = "255.255.255.255";
             obAddress.Description = "Test";
             obAddress.Save();

             // Test that we can send spam now.
             // Create a test account
             // Fetch the default domain
             ;
             _antiSpam.CheckHostInHelo = true;
             _antiSpam.CheckHostInHeloScore = 125;

             // Enable SURBL.
             hMailServer.SURBLServer oSURBLServer = _antiSpam.SURBLServers[0];
             oSURBLServer.Active = true;
             oSURBLServer.Score = 5;
             oSURBLServer.Save();

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

             Assert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-"));

             obAddresses.DeleteByDBID(obAddress.ID);

             // Check that it's deteceted as spam again.
             Assert.IsFalse(oSMTP.Send("*****@*****.**", "*****@*****.**", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-"));

             POP3Simulator.AssertMessageCount("*****@*****.**", "test", 1);
        }
コード例 #54
0
ファイル: Rules.cs プロジェクト: nberardi/hMailServer
        public void CriteriaContainsHTMLBody()
        {
            // Add an account
              hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

              hMailServer.Rule oRule = account.Rules.Add();
              oRule.Name = "Criteria test";
              oRule.Active = true;

              hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add();
              oRuleCriteria.UsePredefined = true;
              oRuleCriteria.PredefinedField = hMailServer.eRulePredefinedField.eFTBody;
              oRuleCriteria.MatchType = hMailServer.eRuleMatchType.eMTContains;
              oRuleCriteria.MatchValue = "MyHTMLBody";
              oRuleCriteria.Save();

              // Add action
              hMailServer.RuleAction oRuleAction = oRule.Actions.Add();
              oRuleAction.Type = hMailServer.eRuleActionType.eRAMoveToImapFolder;
              oRuleAction.IMAPFolder = "INBOX.Wildcard";
              oRuleAction.Save();

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

              SMTPClientSimulator oSMTP = new SMTPClientSimulator();

              string message = "From: Someone <*****@*****.**>" + Environment.NewLine +
                           "Content-Type: text/html; charset=\"Windows-1251\"" + Environment.NewLine +
                           "Content-Transfer-Encoding: quoted-printable" + Environment.NewLine +
                           Environment.NewLine +
                           "<HTML><Center>MyHTMLBody</Center></HTML>" + Environment.NewLine;

              oSMTP.SendRaw("*****@*****.**", account.Address, message);

              // The message should be placed in the Wildcard folder, since the HTML body of the message contains MyHTMLBody.
              IMAPSimulator.AssertMessageCount(account.Address, "test", "Inbox.Wildcard", 1);
              IMAPSimulator.AssertMessageCount(account.Address, "test", "Inbox", 0);
        }
コード例 #55
0
        public void TestSMTPClient()
        {
            hMailServer.Account account1 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

            Assert.AreEqual(0, _status.UndeliveredMessages.Length);

            // No valid recipients...
            Dictionary<string, int> deliveryResults = new Dictionary<string, int>();
            deliveryResults["*****@*****.**"] = 550;

            SMTPServerSimulator server = new SMTPServerSimulator(1, 250);
            server.AddRecipientResult(deliveryResults);
            server.StartListen();

            // Add a route so we can connect to localhost.
            AddRoutePointingAtLocalhostWithAuth(0, 250);

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

            Utilities.AssertRecipientsInDeliveryQueue(0);

            string undeliveredMessages = _status.UndeliveredMessages;

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

            Utilities.AssertRecipientsInDeliveryQueue(0);

            EnsureNoPassword();
        }
コード例 #56
0
        public void TestPlusAddressing()
        {
            // Create a test account
             // Fetch the default domain
             // Enable plus adressing
             _domain.PlusAddressingEnabled = true;
             _domain.PlusAddressingCharacter = "+";

             // Save the change
             _domain.Save();

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

             // Send 5 messages to this account, without using plus addressing.
             SMTPClientSimulator oSMTP = new SMTPClientSimulator();
             for (int i = 0; i < 5; i++)
            oSMTP.Send("*****@*****.**", "*****@*****.**", "INBOX", "Plus addressing message");
             // Wait for completion

             // Check using POP3 that 5 messages exists.
             POP3Simulator.AssertMessageCount("*****@*****.**", "test", 5);

             // Send using plus addressing
             for (int i = 0; i < 5; i++)
            oSMTP.Send("*****@*****.**", "*****@*****.**", "INBOX", "Plus addressing message");
             // Wait for completion

             POP3Simulator.AssertMessageCount("*****@*****.**", "test", 10);

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

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

            // Send to the alias
            for (int i = 0; i < 5; i++)
               oSMTP.Send("*****@*****.**", "*****@*****.**", "INBOX", "Plus addressing message");
            // Wait for completion

            POP3Simulator.AssertMessageCount("*****@*****.**", "test", 5);
             }

             _domain.PlusAddressingEnabled = false;
        }
コード例 #57
0
        public void TestOverlappingBoundaryNames()
        {
            string content =    "Return-Path: <*****@*****.**>\r\n" +
                                "From: \"test\" <*****@*****.**>\r\n" +
                                "To: \"Test\" <*****@*****.**>\r\n" +
                                "Subject: rtest\r\n" +
                                "Date: Thu, 22 Jan 2009 13:20:32 +0100\r\n" +
                                "MIME-Version: 1.0\r\n" +
                                "Content-Type: multipart/mixed;\r\n" +
                                "    boundary=\"----=_NextPart_000_000D_01C97C94.33D5E670\"\r\n" +
                                "\r\n" +
                                "This is a multi-part message in MIME format.\r\n" +
                                "\r\n" +
                                "------=_NextPart_000_000D_01C97C94.33D5E670\r\n" +
                                "Content-Type: multipart/alternative;\r\n" +
                                "    boundary=\"----=_NextPart_000_000D_01C97C94.33D5E670.ALT\"\r\n" +
                                "\r\n"+
                                "\r\n" +
                                "------=_NextPart_000_000D_01C97C94.33D5E670.ALT\r\n" +
                                "Content-Type: text/plain;\r\n" +
                                "    charset=\"iso-8859-1\"\r\n" +
                                "Content-Transfer-Encoding: quoted-printable\r\n" +
                                "\r\n" +
                                "test\r\n" +
                                "------=_NextPart_000_000D_01C97C94.33D5E670.ALT\r\n" +
                                "Content-Type: text/html;\r\n" +
                                "    charset=\"iso-8859-1\"\r\n" +
                                "Content-Transfer-Encoding: quoted-printable\r\n" +
                                "\r\n" +
                                "<a>test</a>\r\n" +
                                "\r\n" +
                                "------=_NextPart_000_000D_01C97C94.33D5E670.ALT--\r\n" +
                                "\r\n" +
                                "------=_NextPart_000_000D_01C97C94.33D5E670\r\n" +
                                "Content-Type: application/octet-stream;\r\n" +
                                "    name=\"test.vbs\"\r\n" +
                                "Content-Transfer-Encoding: 7bit\r\n" +
                                "Content-Disposition: attachment;\r\n" +
                                "    filename=\"test.vbs\"\r\n" +
                                "\r\n" +
                                "s = \"abc\"\r\n" +
                                "\r\n" +
                                "msgbox mid(s,1,100000)\r\n" +
                                "------=_NextPart_000_000D_01C97C94.33D5E670--\r\n" +
                                "\r\n" +
                                "";

            // Add an account
            hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

            hMailServer.Rule oRule = oAccount.Rules.Add();
            oRule.Name = "Criteria test";
            oRule.Active = true;

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

            // Add action
            hMailServer.RuleAction oRuleAction = oRule.Actions.Add();
            oRuleAction.Type = hMailServer.eRuleActionType.eRASetHeaderValue;
            oRuleAction.HeaderName = "SomeHeader";
            oRuleAction.Value = "SomeValue";
            oRuleAction.Save();

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

            SMTPClientSimulator oSMTP = new SMTPClientSimulator();

            // Spam folder
            oSMTP.SendRaw("*****@*****.**", "*****@*****.**", content);

            string sContents = POP3Simulator.AssertGetFirstMessageText("*****@*****.**", "test");

            Assert.IsTrue(sContents.IndexOf("SomeHeader: SomeValue") > 0);
            Assert.IsTrue(sContents.IndexOf("------=_NextPart_000_000D_01C97C94.33D5E670.ALT--") > 0);
        }
コード例 #58
0
ファイル: Rules.cs プロジェクト: nberardi/hMailServer
        public void ActionGlobalRuleMoveToIMAPFolderPublicFolderNonExistant()
        {
            hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp();
             hMailServer.Account account1 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             hMailServer.Rule oRule = application.Rules.Add();
             oRule.Name = "Criteria test";
             oRule.Active = true;

             hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add();
             oRuleCriteria.UsePredefined = true;
             oRuleCriteria.PredefinedField = hMailServer.eRulePredefinedField.eFTMessageSize;
             oRuleCriteria.MatchType = hMailServer.eRuleMatchType.eMTGreaterThan;
             oRuleCriteria.MatchValue = "0";
             oRuleCriteria.Save();

             // Add action
             hMailServer.RuleAction oRuleAction = oRule.Actions.Add();
             oRuleAction.Type = hMailServer.eRuleActionType.eRAMoveToImapFolder;
             oRuleAction.IMAPFolder = "#public.MyFolder";
             oRuleAction.Save();

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

             SMTPClientSimulator oSMTP = new SMTPClientSimulator();

             // Spam folder
             Assert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "SomeString", "Detta ska hamna i public folder."));

             // Wait for the folder to be created.
             hMailServer.IMAPFolder folder = Utilities.AssertFolderExists(_settings.PublicFolders, "MyFolder");

             // Wait for the message to appear.
             Utilities.AssertMessageExistsInFolder(folder, 1);

             // Make sure we can't access it.
             bool ok = false;
             try
             {
            IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "#public.MyFolder", 0);
             }
             catch (Exception)
             {
            ok = true;
             }
             Assert.IsTrue(ok);

             // Set permissions on this folder.
             hMailServer.IMAPFolderPermission permission = folder.Permissions.Add();
             permission.PermissionAccountID = account1.ID;
             permission.PermissionType = hMailServer.eACLPermissionType.ePermissionTypeUser;
             permission.set_Permission(hMailServer.eACLPermission.ePermissionInsert, true);
             permission.set_Permission(hMailServer.eACLPermission.ePermissionRead, true);
             permission.set_Permission(hMailServer.eACLPermission.ePermissionExpunge, true);
             permission.Save();

             // Make sure we can access it now.
             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "#public.MyFolder", 1);
        }
コード例 #59
0
ファイル: Rules.cs プロジェクト: nberardi/hMailServer
        public void ActionSendUsingRoute()
        {
            // add an account to send from
             hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

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

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

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

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

             oRule.Save();

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

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

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

             server.WaitForCompletion();

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

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

             Assert.IsTrue(message.Contains("550"));
             Assert.IsTrue(message.Contains("*****@*****.**"));
        }
コード例 #60
0
ファイル: Rules.cs プロジェクト: nberardi/hMailServer
        public void CriteriaGreaterThan()
        {
            // Add an account
             hMailServer.Account oAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test");

             hMailServer.Rule oRule = oAccount.Rules.Add();
             oRule.Name = "Criteria test";
             oRule.Active = true;

             hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add();
             oRuleCriteria.UsePredefined = false;
             oRuleCriteria.HeaderField = "Subject";
             oRuleCriteria.MatchType = hMailServer.eRuleMatchType.eMTGreaterThan;
             oRuleCriteria.MatchValue = "2";
             oRuleCriteria.Save();

             // Add action
             hMailServer.RuleAction oRuleAction = oRule.Actions.Add();
             oRuleAction.Type = hMailServer.eRuleActionType.eRAMoveToImapFolder;
             oRuleAction.IMAPFolder = "INBOX.GreaterThan";
             oRuleAction.Save();

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

             SMTPClientSimulator oSMTP = new SMTPClientSimulator();

             // Spam folder
             oSMTP.Send("*****@*****.**", "*****@*****.**", "0", "Detta ska inte hamna i mappen Inbox");
             oSMTP.Send("*****@*****.**", "*****@*****.**", "1", "Detta ska inte hamna i mappen Inbox");
             oSMTP.Send("*****@*****.**", "*****@*****.**", "2", "Detta ska inte hamna i mappen Inbox");
             oSMTP.Send("*****@*****.**", "*****@*****.**", "3", "Detta ska hamna i mappen Inbox\\GreaterThan");
             oSMTP.Send("*****@*****.**", "*****@*****.**", "4", "Detta ska hamna i mappen Inbox\\GreaterThan");

             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 3);
             IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox.GreaterThan", 2);
        }