public void TestWhitelistOutOfRangeAddress() { // Enable SURBL. var oSURBLServer = _antiSpam.SURBLServers[0]; oSURBLServer.Active = true; oSURBLServer.Score = 5; oSURBLServer.Save(); // Make sure we are now blacklisted. var smtpClient = new SMTPClientSimulator(false, 25); CustomAssert.IsFalse(smtpClient.Send("*****@*****.**", "*****@*****.**", "Hello", SurblTestPointBody)); // White list all IPv4 addresses var obAddress = _antiSpam.WhiteListAddresses.Add(); obAddress.EmailAddress = "*"; obAddress.LowerIPAddress = "1.1.1.1"; obAddress.UpperIPAddress = "1.1.1.5"; obAddress.Description = "Test"; obAddress.Save(); // Make sure we are still blacklisted. CustomAssert.IsFalse(smtpClient.Send("*****@*****.**", "*****@*****.**", "Hello", SurblTestPointBody)); }
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.")); }
public void TestSubjectSearchMultipleMatches() { hMailServer.Domain oDomain = _application.Domains[0]; hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search"); IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1); oSMTP.Send("*****@*****.**", "*****@*****.**", "TestA", "This is a test of IMAP Search"); IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2); oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search"); IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 3); IMAPSimulator oSimulator = new IMAPSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("*****@*****.**", "test"); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); Assert.AreEqual("1 3", oSimulator.Sort("(SUBJECT) UTF-8 ALL HEADER SUBJECT \"Test1\"")); Assert.AreEqual("2", oSimulator.Sort("(SUBJECT) UTF-8 ALL HEADER SUBJECT \"TestA\"")); Assert.AreEqual("3 1", oSimulator.Sort("(REVERSE SUBJECT) UTF-8 ALL HEADER SUBJECT \"Test1\"")); Assert.AreEqual("2", oSimulator.Sort("(REVERSE SUBJECT) UTF-8 ALL HEADER SUBJECT \"TestA\"")); Assert.AreEqual("3 1", oSimulator.Sort("(REVERSE SUBJECT) UTF-8 ALL (HEADER SUBJECT) \"Test1\"")); Assert.AreEqual("2", oSimulator.Sort("(REVERSE SUBJECT) UTF-8 ALL (HEADER SUBJECT) \"TestA\"")); }
public void TestSearchORWithLiterals3() { 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("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search"); IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1); oSMTP.Send("*****@*****.**", "*****@*****.**", "Test2", "This is a test of IMAP Search"); IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2); IMAPSimulator oSimulator = new IMAPSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("*****@*****.**", "test"); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); string result = oSimulator.Send("A01 SEARCH ALL OR (HEADER SUBJECT {5}"); result = oSimulator.Send("Test5) (HEADER SUBJECT {5}"); result = oSimulator.Send("Test2)"); Assert.IsTrue(result.StartsWith("* SEARCH 2")); }
public void TestSURBLCombinedWithSignature() { Application application = SingletonProvider <TestSetup> .Instance.GetApp(); // Create a test account // Fetch the default domain _domain.SignatureEnabled = true; _domain.SignaturePlainText = "MyDomainSignature"; _domain.AddSignaturesToLocalMail = true; _domain.Save(); 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"; // 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(); oSMTP.Send("*****@*****.**", "*****@*****.**", "SURBL-No-Match", "This is a test message without a SURBL url."); string sMessageContents = POP3ClientSimulator.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"); } CustomAssert.IsTrue(sMessageContents.Contains(_domain.SignaturePlainText)); oSMTP.Send("*****@*****.**", "*****@*****.**", "SURBL-No-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-"); 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"); } CustomAssert.IsTrue(sMessageContents.Contains(_domain.SignaturePlainText)); }
public void TestSortReverseSize() { hMailServer.Domain oDomain = _application.Domains[0]; hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); StringBuilder longBodyString = new StringBuilder(); longBodyString.Append('A', 10000); // Send a message to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", longBodyString.ToString()); IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1); oSMTP.Send("*****@*****.**", "*****@*****.**", "Test2", "Test body"); IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2); IMAPSimulator oSimulator = new IMAPSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("*****@*****.**", "test"); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); Assert.AreEqual("2 1", oSimulator.Sort("(SIZE) UTF-8 ALL")); Assert.AreEqual("1 2", oSimulator.Sort("(REVERSE SIZE) UTF-8 ALL")); }
public void TestWhitelistSpecificIpV4Address() { var addresses = GetAllLocalAddresses(System.Net.Sockets.AddressFamily.InterNetwork); var firstAddress = addresses[0]; // Enable SURBL. var oSURBLServer = _antiSpam.SURBLServers[0]; oSURBLServer.Active = true; oSURBLServer.Score = 5; oSURBLServer.Save(); // Make sure we are now blacklisted. var smtpClient = new SMTPClientSimulator(false, 25, IPAddress.Parse(firstAddress)); CustomAssert.IsFalse(smtpClient.Send("*****@*****.**", "*****@*****.**", "Hello", SurblTestPointBody)); // White list all IPv4 addresses foreach (var address in addresses) { var obAddress = _antiSpam.WhiteListAddresses.Add(); obAddress.EmailAddress = "*"; obAddress.LowerIPAddress = address; obAddress.UpperIPAddress = address; obAddress.Description = "Test"; obAddress.Save(); } // Make sure we can now send again. CustomAssert.IsTrue(smtpClient.Send("*****@*****.**", "*****@*****.**", "Hello", SurblTestPointBody)); POP3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 1); }
public void TestDistributionListModeMembers() { var recipients = new List <string>(); recipients.Add("*****@*****.**"); recipients.Add("*****@*****.**"); recipients.Add("*****@*****.**"); var list = SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", recipients); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var announcer = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Switch list mode so that only a single announcer can send to list. list.Mode = eDistributionListMode.eLMMembership; list.RequireSenderAddress = announcer.Address; list.RequireSMTPAuth = false; list.Save(); var smtpClient = new SMTPClientSimulator(); CustomAssert.IsFalse(smtpClient.Send("*****@*****.**", list.Address, "Mail 1", "Mail 1")); CustomAssert.IsFalse(smtpClient.Send(announcer.Address, list.Address, "Mail 1", "Mail 1")); CustomAssert.IsTrue(smtpClient.Send(recipients[0], list.Address, "Mail 1", "Mail 1")); foreach (var recipient in recipients) { IMAPClientSimulator.AssertMessageCount(recipient, "test", "Inbox", 1); } }
public void TestSearchORWithParenthesisSubject() { Application application = SingletonProvider <TestSetup> .Instance.GetApp(); Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to this account. var oSMTP = new SMTPClientSimulator(); oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search"); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1); oSMTP.Send("*****@*****.**", "*****@*****.**", "Test2", "This is a test of IMAP Search"); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2); var oSimulator = new IMAPClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("*****@*****.**", "test"); CustomAssert.IsTrue(oSimulator.SelectFolder("INBOX")); if (oSimulator.Search("OR (SUBJECT \"Test1\") (ON 28-May-2001) ALL") != "1") { throw new Exception("ERROR - Search or flag failed"); } if (oSimulator.Search("OR (SUBJECT \"Test2\") (ON 28-May-2001) ALL") != "2") { throw new Exception("ERROR - Search or flag failed"); } }
public void TestSearchWithLiterals() { Application application = SingletonProvider <TestSetup> .Instance.GetApp(); Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to this account. var oSMTP = new SMTPClientSimulator(); oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search"); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1); oSMTP.Send("*****@*****.**", "*****@*****.**", "Test2", "This is a test of IMAP Search"); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2); var oSimulator = new IMAPClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("*****@*****.**", "test"); CustomAssert.IsTrue(oSimulator.SelectFolder("INBOX")); string result = oSimulator.SendSingleCommandWithLiteral("A01 SEARCH HEADER SUBJECT {5}", "Test1"); CustomAssert.IsTrue(result.StartsWith("* SEARCH 1\r\n")); result = oSimulator.SendSingleCommandWithLiteral("A01 SEARCH HEADER SUBJECT {5}", "Test2"); CustomAssert.IsTrue(result.StartsWith("* SEARCH 2\r\n")); }
public void TestSearchORWithParenthesisSubjectNested() { 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("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search"); IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1); oSMTP.Send("*****@*****.**", "*****@*****.**", "Test2", "This is a test of IMAP Search"); IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2); IMAPSimulator oSimulator = new IMAPSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("*****@*****.**", "test"); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); if (oSimulator.Search("ALL (OR (HEADER SUBJECT \"Test1\") (HEADER SUBJECT \"Test2\"))") != "1 2") { throw new Exception("ERROR - Search or flag failed"); } }
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)); }
public void TestSubjectSearch() { Domain oDomain = _application.Domains[0]; Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to this account. var oSMTP = new SMTPClientSimulator(); oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search"); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1); oSMTP.Send("*****@*****.**", "*****@*****.**", "Test2", "This is a test of IMAP Search"); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2); var oSimulator = new IMAPClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("*****@*****.**", "test"); CustomAssert.IsTrue(oSimulator.SelectFolder("INBOX")); CustomAssert.AreEqual("1", oSimulator.Sort("(REVERSE SUBJECT) UTF-8 ALL HEADER SUBJECT \"Test1\"")); CustomAssert.AreEqual("2", oSimulator.Sort("(REVERSE SUBJECT) UTF-8 ALL HEADER SUBJECT \"Test2\"")); CustomAssert.AreEqual("1", oSimulator.Sort("(REVERSE SUBJECT) UTF-8 ALL (HEADER SUBJECT \"Test1\")")); CustomAssert.AreEqual("2", oSimulator.Sort("(REVERSE SUBJECT) UTF-8 ALL (HEADER SUBJECT \"Test2\")")); }
public void TestGreyListing() { _antiSpam.GreyListingEnabled = false; Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var smtp = new SMTPClientSimulator(); var recipients = new List <string>(); recipients.Add(oAccount1.Address); bool result = smtp.Send("*****@*****.**", recipients, "Test", "Body"); CustomAssert.IsTrue(result); POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); _antiSpam.GreyListingEnabled = true; result = smtp.Send("*****@*****.**", recipients, "Test", "Body"); CustomAssert.IsFalse(result); _antiSpam.GreyListingEnabled = false; result = smtp.Send("*****@*****.**", recipients, "Test", "Body"); CustomAssert.IsTrue(result); POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); }
public void TestSortSubjectSearch() { hMailServer.Domain oDomain = _application.Domains[0]; hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.Send("*****@*****.**", "*****@*****.**", "aa", "This is a test of IMAP Search"); IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1); oSMTP.Send("*****@*****.**", "*****@*****.**", "bb", "This is a test of IMAP Search"); IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2); IMAPSimulator oSimulator = new IMAPSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("*****@*****.**", "test"); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); Assert.AreEqual("1 2", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR HEADER SUBJECT aa HEADER SUBJECT bb")); Assert.AreEqual("1 2", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR (HEADER SUBJECT aa) (HEADER SUBJECT bb)")); Assert.AreEqual("1 2", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED (OR HEADER SUBJECT aa HEADER SUBJECT bb)")); Assert.AreEqual("1", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR HEADER SUBJECT aa HEADER SUBJECT cc")); Assert.AreEqual("1", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR (HEADER SUBJECT aa) (HEADER SUBJECT cc)")); Assert.AreEqual("1", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED (OR HEADER SUBJECT aa HEADER SUBJECT cc)")); Assert.AreEqual("2", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR HEADER SUBJECT bb HEADER SUBJECT cc")); Assert.AreEqual("2", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED OR (HEADER SUBJECT bb) (HEADER SUBJECT cc)")); Assert.AreEqual("2", oSimulator.Sort("(DATE) UTF-8 ALL UNANSWERED (OR HEADER SUBJECT bb HEADER SUBJECT cc)")); }
public void TestMissingMXRecord() { 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.SpamDeleteThreshold = 1; _antiSpam.UseMXChecks = true; _antiSpam.UseMXChecksScore = 2; // Send a messages to this account. var oSMTP = new SMTPClientSimulator(); if (!oSMTP.Send("*****@*****.**", "*****@*****.**", "INBOX", "This is a test message.")) { throw new Exception("ERROR - Was not able to send correct email."); } if (oSMTP.Send("test@domain_without_mx_records421dfsam430sasd.com", oAccount1.Address, "INBOX", "This is a test message.")) { throw new Exception("ERROR - Was not able to send incorrect email."); } _antiSpam.UseMXChecks = false; POP3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); }
public void TestSortReverseArrival() { hMailServer.Domain oDomain = _application.Domains[0]; hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search"); IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1); // The two messages needs to be sent a second apart, so we actually need to pause a bit here. System.Threading.Thread.Sleep(1000); oSMTP.Send("*****@*****.**", "*****@*****.**", "Test2", "This is a test of IMAP Search"); IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 2); IMAPSimulator oSimulator = new IMAPSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("*****@*****.**", "test"); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); Assert.AreEqual("1 2", oSimulator.Sort("(ARRIVAL) UTF-8 ALL")); Assert.AreEqual("2 1", oSimulator.Sort("(REVERSE ARRIVAL) UTF-8 ALL")); }
public void TestBlockingDeliveries() { SecurityRange range = SingletonProvider <TestSetup> .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(); Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var oSMTP = new SMTPClientSimulator(); string result1, result2, result3, result4; CustomAssert.IsFalse(oSMTP.Send(account1.Address, account1.Address, "Mail 1", "Mail 1", out result1)); CustomAssert.IsFalse(oSMTP.Send(account1.Address, "*****@*****.**", "Mail 1", "Mail 1", out result2)); CustomAssert.IsFalse(oSMTP.Send("*****@*****.**", account1.Address, "Mail 1", "Mail 1", out result3)); CustomAssert.IsFalse(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result4)); CustomAssert.IsTrue(result1.Contains("550 Delivery is not allowed to this address.")); CustomAssert.IsTrue(result2.Contains("550 Delivery is not allowed to this address.")); CustomAssert.IsTrue(result3.Contains("550 Delivery is not allowed to this address.")); CustomAssert.IsTrue(result4.Contains("550 Delivery is not allowed to this address.")); }
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); } }
public void TestAutoReply() { // Create a test account // Fetch the default domain Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, TestSetup.RandomString() + "@test.com", "test"); Account oAccount2 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, TestSetup.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. var oSMTP = new SMTPClientSimulator(); oSMTP.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body"); var oPOP3 = new POP3ClientSimulator(); POP3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); POP3ClientSimulator.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"); POP3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 2); POP3ClientSimulator.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."); } CustomAssert.IsTrue(s.Contains("Auto-Submitted: auto-replied")); oAccount2.VacationMessageIsOn = false; oAccount2.Save(); }
public void TestDistributionListsMembershipDomainAliases() { var oIMAP = new IMAPClientSimulator(); var oSMTP = new SMTPClientSimulator(); Application application = SingletonProvider <TestSetup> .Instance.GetApp(); DomainAlias oDA = _domain.DomainAliases.Add(); oDA.AliasName = "dummy-example.com"; oDA.Save(); Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // // TEST LIST SECURITY IN COMBINATION WITH DOMAIN NAME ALIASES // var oRecipients = new List <string>(); oRecipients.Clear(); oRecipients.Add("*****@*****.**"); DistributionList oList3 = SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", oRecipients); oList3.Mode = eDistributionListMode.eLMMembership; oList3.Save(); // THIS MESSAGE SHOULD FAIL - Membership required, unknown sender domain CustomAssert.IsFalse(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1")); oList3.Delete(); // THIS MESSAGE SHOULD SUCCED - Membership required, sender domain is now an alias for test.com. oRecipients = new List <string>(); oRecipients.Clear(); oRecipients.Add("*****@*****.**"); oRecipients.Add("*****@*****.**"); oList3 = SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", oRecipients); oList3.Mode = eDistributionListMode.eLMMembership; oList3.Save(); CustomAssert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1")); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1); }
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; }
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); }
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); }
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]")); }
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>")); }
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); }
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 TestMirror() { // Create a test account // Fetch the default domain hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account oAccount2 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); _settings.MirrorEMailAddress = "*****@*****.**"; _settings.AddDeliveredToHeader = true; // Send 5 messages to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); for (int i = 0; i < 5; i++) { oSMTP.Send("*****@*****.**", "*****@*****.**", "INBOX", "Mirror test message"); } // Check using POP3 that 5 messages exists. POP3Simulator.AssertMessageCount("*****@*****.**", "test", 5); string message = POP3Simulator.AssertGetFirstMessageText(oAccount2.Address, "test"); Assert.IsTrue(message.Contains("Delivered-To: [email protected]")); }
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"); } }
public void TestMirrorMultipleRecipients() { // 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"); hMailServer.Account oAccount3 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account mirrorAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); _settings.MirrorEMailAddress = "*****@*****.**"; _settings.AddDeliveredToHeader = true; // Send 5 messages to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.Send("*****@*****.**", new List <string>() { oAccount1.Address, oAccount2.Address, oAccount3.Address }, "INBOX", "Mirror test message"); POP3Simulator.AssertMessageCount(mirrorAccount.Address, "test", 1); string message = POP3Simulator.AssertGetFirstMessageText(mirrorAccount.Address, "test"); Assert.IsTrue(message.Contains("Delivered-To: [email protected],[email protected],[email protected]")); Utilities.AssertRecipientsInDeliveryQueue(0); }
public void TestMirrorMultipleRecipientsOver255Chars() { // Create a test account // Fetch the default domain List <string> recipients = new List <string>(); for (int i = 0; i < 20; i++) { string address = string.Format("mirror{0}@test.com", i); SingletonProvider <Utilities> .Instance.AddAccount(_domain, address, "test"); recipients.Add(address); } hMailServer.Account mirrorAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); _settings.MirrorEMailAddress = "*****@*****.**"; _settings.AddDeliveredToHeader = true; // Send 5 messages to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.Send("*****@*****.**", recipients, "INBOX", "Mirror test message"); POP3Simulator.AssertMessageCount(mirrorAccount.Address, "test", 1); string message = POP3Simulator.AssertGetFirstMessageText(mirrorAccount.Address, "test"); Assert.IsTrue(message.Contains("Delivered-To: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],mirror14@test\r\n")); Utilities.AssertRecipientsInDeliveryQueue(0); }
public void TestSearchON() { 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("*****@*****.**", "test", "INBOX", 1); IMAPSimulator oSimulator = new IMAPSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("*****@*****.**", "test"); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); string formattedTomorrow = (DateTime.Now + new TimeSpan(1, 0, 0, 0)).ToString("dd-MMM-yyyy", System.Globalization.CultureInfo.InvariantCulture).ToUpper(); string formattedToday = DateTime.Now.ToString("dd-MMM-yyyy", System.Globalization.CultureInfo.InvariantCulture).ToUpper(); if (oSimulator.Search("ON " + formattedTomorrow) != "") { throw new Exception("ERROR - Search or flag failed"); } if (oSimulator.Search("ON " + formattedToday) != "1") { throw new Exception("ERROR - Search or flag failed"); } }
private string SendMessage(string body) { hMailServer.Account account1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Dictionary <string, int> deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. AddRoutePointingAtLocalhost(5, 250); // Send message to this route. SMTPClientSimulator smtp = new SMTPClientSimulator(); List <string> recipients = new List <string>(); recipients.Add("*****@*****.**"); Assert.IsTrue(smtp.Send("*****@*****.**", recipients, "Test", body)); // Wait for the client to disconnect. server.WaitForCompletion(); string messageData = server.MessageData; Utilities.AssertRecipientsInDeliveryQueue(0); return(messageData); }
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); }
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"); } }
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)); }
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"); }
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 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); }
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:")); }
public void TestCreateCopyAccountRule() { // Add an account hMailServer.Account account1 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account account2 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account account3 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); // Set up a rule to forward from account1 to 2 and 3. hMailServer.Rule oRule = account1.Rules.Add(); oRule.Name = "Criteria test"; oRule.Active = true; oRule.UseAND = 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(); // Only send one copy. oRuleCriteria = oRule.Criterias.Add(); oRuleCriteria.UsePredefined = false; oRuleCriteria.HeaderField = "X-hMailServer-LoopCount"; oRuleCriteria.MatchType = hMailServer.eRuleMatchType.eMTLessThan; oRuleCriteria.MatchValue = "1"; oRuleCriteria.Save(); // Set up the actions to forward. hMailServer.RuleAction oRuleAction = oRule.Actions.Add(); oRuleAction.Type = hMailServer.eRuleActionType.eRACreateCopy; oRuleAction.To = "*****@*****.**"; oRuleAction.Save(); // Save the rule in the database oRule.Save(); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); // Test to send the message to account 1. Make sure a copy is created by this rule. oSMTP.Send(account1.Address, account1.Address, "Test", "Test message."); Utilities.AssertRecipientsInDeliveryQueue(0, true); IMAPSimulator.AssertMessageCount(account1.Address, "test", "Inbox", 2); string firstTemp = POP3Simulator.AssertGetFirstMessageText(account1.Address, "test"); string secondTemp = POP3Simulator.AssertGetFirstMessageText(account1.Address, "test"); // This is where it gets really ugly. The order of the two deliveries // are not defined. The message created by the rule could be delivered // before the first message. string first = ""; string second = ""; if (secondTemp.Contains("X-hMailServer-LoopCount")) { first = firstTemp; second = secondTemp; } else { first = secondTemp; second = firstTemp; } Assert.IsFalse(first.Contains("X-hMailServer-LoopCount: 1"), first); Assert.IsFalse(first.Contains("X-CopyRule: Criteria test"), first); Assert.IsTrue(second.Contains("X-hMailServer-LoopCount"), second); Assert.IsTrue(second.Contains("X-CopyRule: Criteria test"), second); }
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); }
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); }
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); }
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); }
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); }
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; }
public void TestCreateCopyGlobalRule() { // Add an account hMailServer.Account account1 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account account2 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account account3 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); // Set up a rule to forward from account1 to 2 and 3. hMailServer.Rule oRule = _application.Rules.Add(); oRule.Name = "CriteriaTest"; oRule.Active = true; oRule.UseAND = 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(); // Only send one copy. oRuleCriteria = oRule.Criterias.Add(); oRuleCriteria.UsePredefined = false; oRuleCriteria.HeaderField = "X-hMailServer-LoopCount"; oRuleCriteria.MatchType = hMailServer.eRuleMatchType.eMTLessThan; oRuleCriteria.MatchValue = "1"; oRuleCriteria.Save(); // Set up the actions to forward. hMailServer.RuleAction oRuleAction = oRule.Actions.Add(); oRuleAction.Type = hMailServer.eRuleActionType.eRACreateCopy; oRuleAction.To = "*****@*****.**"; oRuleAction.Save(); // Save the rule in the database oRule.Save(); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); // Test to send the message to account 1. Make sure a copy is created by this rule. oSMTP.Send(account1.Address, new List<string>() {account1.Address, account2.Address}, "Test", "Test message."); Utilities.AssertRecipientsInDeliveryQueue(0, true); IMAPSimulator.AssertMessageCount(account1.Address, "test", "Inbox", 2); IMAPSimulator.AssertMessageCount(account2.Address, "test", "Inbox", 2); /* * The delivery order is not guaranteed. The copied message may be delivered * before the original message. Check both situations. * */ string first = POP3Simulator.AssertGetFirstMessageText(account1.Address, "test"); string second = POP3Simulator.AssertGetFirstMessageText(account1.Address, "test"); if (first.Contains("X-hMailServer-LoopCount: 1")) { Assert.IsFalse(second.Contains("X-CopyRule: CriteriaTest"), first); Assert.IsTrue(first.Contains("X-hMailServer-LoopCount"), first); } else { Assert.IsTrue(second.Contains("X-hMailServer-LoopCount: 1"), second); Assert.IsTrue(second.Contains("X-CopyRule: CriteriaTest"), first); } first = POP3Simulator.AssertGetFirstMessageText(account2.Address, "test"); second = POP3Simulator.AssertGetFirstMessageText(account2.Address, "test"); if (first.Contains("X-hMailServer-LoopCount: 1")) { Assert.IsFalse(second.Contains("X-hMailServer-LoopCount"), first); Assert.IsTrue(first.Contains("X-CopyRule: CriteriaTest"), first); } else { Assert.IsTrue(second.Contains("X-hMailServer-LoopCount: 1"), second); Assert.IsTrue(second.Contains("X-CopyRule: CriteriaTest"), first); } }
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("*****@*****.**")); }
public void TestDeliveryAttempts() { // Add an account hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account adminAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); // Set up a rule to forward from account1 to 2 and 3. hMailServer.Rule oRule = _application.Rules.Add(); oRule.Name = "Criteria test"; oRule.Active = true; oRule.UseAND = true; hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add(); oRuleCriteria.UsePredefined = true; oRuleCriteria.PredefinedField = hMailServer.eRulePredefinedField.eFTDeliveryAttempts; oRuleCriteria.MatchType = hMailServer.eRuleMatchType.eMTEquals; oRuleCriteria.MatchValue = "2"; oRuleCriteria.Save(); // The second time we try to deliver an email, forward a copy to the admin! hMailServer.RuleAction oRuleAction = oRule.Actions.Add(); oRuleAction.Type = hMailServer.eRuleActionType.eRAForwardEmail; oRuleAction.To = adminAccount.Address; oRuleAction.Save(); // And then delete it. oRuleAction = oRule.Actions.Add(); oRuleAction.Type = hMailServer.eRuleActionType.eRADeleteEmail; oRuleAction.Save(); // Save the rule in the database oRule.Save(); Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 452; SMTPServerSimulator smtpServer = new SMTPServerSimulator(1, 250); smtpServer.AddRecipientResult(deliveryResults); smtpServer.StartListen(); // Add a route so we can connect to localhost. SMTPClientTests.AddRoutePointingAtLocalhost(2, 250, false); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); // Test to send the message to account 1. Make sure a copy is created by this rule. oSMTP.Send(account.Address, new List<string>() { "*****@*****.**" }, "Test", "Test message."); smtpServer.WaitForCompletion(); Utilities.AssertRecipientsInDeliveryQueue(0, true); string first = POP3Simulator.AssertGetFirstMessageText(adminAccount.Address, "test"); Assert.IsTrue(first.Contains("X-hMailServer-LoopCount: 1"), first); POP3Simulator.AssertMessageCount(account.Address, "test", 0); }
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); }
public void ActionBindToAddress() { // 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.eMTEquals; oRuleCriteria.MatchValue = "SomeString"; oRuleCriteria.Save(); // Add action hMailServer.RuleAction oRuleAction = oRule.Actions.Add(); oRuleAction.Type = hMailServer.eRuleActionType.eRABindToAddress; oRuleAction.Value = "255.254.253.252"; oRuleAction.Save(); oRule.Save(); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); // Spam folder oSMTP.Send("*****@*****.**", "*****@*****.**", "SomeString", "This mail should not be delivered."); Utilities.AssertRecipientsInDeliveryQueue(0); string errorLog = Utilities.ReadAndDeleteErrorLog(); Assert.IsTrue(errorLog.Contains("Failed to bind to IP address 255.254.253.252.")); }
public void ActionAccountRuleMoveToNonExistingPublicFolder() { 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.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 oSMTP.Send("*****@*****.**", "*****@*****.**", "SomeString", "This should end up in the inbox since user lacks right."); IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1); }
public void TestForward() { // Add an account hMailServer.Account account1 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account account2 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account account3 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); // Set up a rule to forward from account1 to 2 and 3. 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(); // Set up the actions to forward. hMailServer.RuleAction oRuleAction = oRule.Actions.Add(); oRuleAction.Type = hMailServer.eRuleActionType.eRAForwardEmail; oRuleAction.To = "*****@*****.**"; oRuleAction.Save(); hMailServer.RuleAction oRuleAction2 = oRule.Actions.Add(); oRuleAction2.Type = hMailServer.eRuleActionType.eRAForwardEmail; oRuleAction2.To = "*****@*****.**"; oRuleAction2.Save(); // Save the rule in the database oRule.Save(); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); // Test to send the messge to account 1. oSMTP.Send(account1.Address, account1.Address, "Test", "Test message."); IMAPSimulator.AssertMessageCount(account1.Address, "test", "Inbox", 1); Utilities.AssertRecipientsInDeliveryQueue(0); IMAPSimulator.AssertMessageCount(account3.Address, "test", "Inbox", 1); IMAPSimulator.AssertMessageCount(account2.Address, "test", "Inbox", 1); }
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(); }
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); }
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"); }
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); }