public void TestValidSignatureSHA256() { _antiSpam.DKIMVerificationEnabled = true; _antiSpam.DKIMVerificationFailureScore = 100; string messageText = @"Return-Path: <*****@*****.**>" + "\r\n" + "X-Original-To: [email protected]" + "\r\n" + "Delivered-To: [email protected]" + "\r\n" + "Received: from voicemail.cis.att.net (unknown [12.34.200.188])" + "\r\n" + " by mx2.messiah.edu (Postfix) with ESMTP id 02F12E15D8"+ "\r\n" + " for <*****@*****.**>; Wed, 3 May 2006 15:06:32 -0400 (EDT)"+ "\r\n" + "Received: from (localhost[127.0.0.1]) by voicemail.cis.att.net (vm2) with SMTP" + "\r\n" + " id <2006050319071918800spa0re>; Wed, 3 May 2006 19:07:19 +0000" + "\r\n" + "DKIM-Signature: a=rsa-sha256; c=relaxed; d=vmt2.cis.att.net; t=1146680862; " + "\r\n" + " h=Date : From : MIME-Version : To : Subject : Content-Type : Content-Transfer-Encoding; bh=HryPFX2R6r7JPsX1Z7+yReZddQR2PjvCvdXgaxW5QYU=; s=shan; " + "\r\n" + " b=QXd8h2UbBO7fIPz/Iy3wNwbVU6dih6ozokPXqAvI6p9iG5SqFahyTXwqZeltC4az3Sjay7Vx+b5e" + "\r\n" + " 1s2rQuhT4SKD47gJYs4kw0JgV2WLanF3oR1hWD0tL0vuDeUgH6kr" + "\r\n" + "Date: Wed, 15 Feb 2006 17:32:54 -0500" + "\r\n" + "From: Tony Hansen <*****@*****.**>" + "\r\n" + "MIME-Version: 1.0" + "\r\n" + "To: [email protected], [email protected], [email protected]" + "\r\n" + "Subject: this is a test message minimum.ietf-01.sha256-relaxed" + "\r\n" + "Content-Type: text/plain; charset=ISO-8859-1" + "\r\n" + "Content-Transfer-Encoding: 7bit" + "\r\n" + "Message-Id: <*****@*****.**>" + "\r\n" + "" + "\r\n" + "The quick brown fox jumped over the lazy dog." + "\r\n"; hMailServer.Account account1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Assert.IsTrue(SMTPClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText)); string text = POP3Simulator.AssertGetFirstMessageText(account1.Address, "test"); }
public void TestSearchUTF8TEXT() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string body = Utilities.GetResource("Messages.MessageContainingGreekSubject.txt"); SMTPClientSimulator.StaticSendRaw(account.Address, account.Address, body); POP3Simulator.AssertMessageCount(account.Address, "test", 1); IMAPSimulator oSimulator = new IMAPSimulator(); Assert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test")); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); string result = oSimulator.Search("CHARSET UTF-8 ALL TEXT GRΣΣK"); Assert.AreEqual("1", result); result = oSimulator.Search("CHARSET UTF-8 ALL TEXT 標準語"); Assert.AreEqual("1", result); result = oSimulator.Search("CHARSET UTF-8 ALL TEXT GRΣΣK標準語"); Assert.AreEqual("1", result); result = oSimulator.Search("CHARSET UTF-8 ALL TEXT GRΣΣKWHAT標準語"); Assert.AreEqual("", result); }
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 TestPOP3TransactionSafety() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Assert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody")); POP3Simulator.AssertMessageCount(account.Address, "test", 1); POP3Simulator sim = new POP3Simulator(); sim.ConnectAndLogon(account.Address, "test"); // Now delete the message using an IMAP client. IMAPSimulator imapSimulator = new IMAPSimulator(); Assert.IsTrue(imapSimulator.ConnectAndLogon(account.Address, "test")); Assert.IsTrue(imapSimulator.SelectFolder("INBOX")); Assert.IsTrue(imapSimulator.SetDeletedFlag(1)); Assert.IsTrue(imapSimulator.Expunge()); Assert.AreEqual(0, imapSimulator.GetMessageCount("Inbox")); Assert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody")); IMAPSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); // This deletion should not have any effect, since the POP3 connection is referencing an old message. sim.DELE(1); sim.QUIT(); Assert.AreEqual(1, imapSimulator.GetMessageCount("Inbox")); }
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 TestChangeRecentFlag() { hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Assert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", oAccount.Address, "Test", "test")); POP3Simulator.AssertMessageCount(oAccount.Address, "test", 1); IMAPSimulator simulator = new IMAPSimulator(); simulator.ConnectAndLogon(oAccount.Address, "test"); string result = simulator.ExamineFolder("Inbox"); Assert.IsTrue(result.Contains("* 1 RECENT"), result); simulator.Close(); simulator.Disconnect(); simulator = new IMAPSimulator(); simulator.ConnectAndLogon(oAccount.Address, "test"); Assert.IsTrue(simulator.SelectFolder("Inbox", out result)); Assert.IsTrue(result.Contains("* 1 RECENT"), result); simulator.Close(); simulator.Disconnect(); simulator = new IMAPSimulator(); simulator.ConnectAndLogon(oAccount.Address, "test"); result = simulator.ExamineFolder("Inbox"); Assert.IsTrue(result.Contains("* 0 RECENT"), result); simulator.Close(); simulator.Disconnect(); }
public void TestPOP3Server() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator smtpSim = new SMTPClientSimulator(); Assert.IsTrue(smtpSim.Send("*****@*****.**", account.Address, "Test", "MyBody")); for (int i = 0; i < 10; i++) { try { POP3Simulator.AssertMessageCount(account.Address, "test", 1); POP3Simulator pop3Sim = new POP3Simulator(true, 11000); string text = pop3Sim.GetFirstMessageText(account.Address, "test"); Assert.IsTrue(text.Contains("MyBody")); break; } catch (AssertionException) { throw; } catch (Exception) { if (i == 9) { throw; } } } }
public void TestChangeSeenFlag() { hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Assert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", oAccount.Address, "Test", "test")); POP3Simulator.AssertMessageCount(oAccount.Address, "test", 1); IMAPSimulator simulator = new IMAPSimulator(); simulator.ConnectAndLogon(oAccount.Address, "test"); simulator.ExamineFolder("Inbox"); string flags = simulator.GetFlags(1); string body = simulator.Fetch("1 RFC822"); string flagsAfter = simulator.GetFlags(1); simulator.Close(); simulator.Disconnect(); Assert.AreEqual(flags, flagsAfter); IMAPSimulator secondSimulator = new IMAPSimulator(); secondSimulator.ConnectAndLogon(oAccount.Address, "test"); secondSimulator.SelectFolder("Inbox"); string secondFlags = secondSimulator.GetFlags(1); string secondBody = secondSimulator.Fetch("1 RFC822"); string secondFlagsAfter = secondSimulator.GetFlags(1); secondSimulator.Close(); secondSimulator.Disconnect(); Assert.AreNotEqual(secondFlags, secondFlagsAfter); }
public void TestExpunge() { hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Assert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", oAccount.Address, "Test", "test")); POP3Simulator.AssertMessageCount(oAccount.Address, "test", 1); IMAPSimulator simulator = new IMAPSimulator(); simulator.ConnectAndLogon(oAccount.Address, "test"); simulator.SelectFolder("Inbox"); Assert.IsTrue(simulator.SetFlagOnMessage(1, true, @"\Deleted")); IMAPSimulator secondSimulator = new IMAPSimulator(); secondSimulator.ConnectAndLogon(oAccount.Address, "test"); string result = secondSimulator.ExamineFolder("INBOX"); Assert.IsTrue(result.Contains("1 EXISTS"), result); Assert.IsFalse(secondSimulator.Expunge()); simulator.SelectFolder("INBOX"); Assert.IsTrue(simulator.Expunge()); simulator.Close(); secondSimulator.Close(); }
public void TestAntiVirusDisabled() { List <string> messages = new List <string>(); string messageText = "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "Should be blocked by SPF."; messages.Add(messageText); int port = 1110; POP3Server pop3Server = new POP3Server(1, port, messages); pop3Server.StartListen(); hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.FetchAccount fa = CreateFetchAccount(account, port, false, false); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); POP3Simulator.AssertMessageCount(account.Address, "test", 1); hMailServer.Message message = account.IMAPFolders.get_ItemByName("INBOX").Messages[0]; Assert.IsFalse(message.get_Flag(hMailServer.eMessageFlag.eMFVirusScan)); }
public void TestSpamProtectionPreTransmissionHELOPassFirst() { _application.Settings.AntiSpam.SpamMarkThreshold = 1; _application.Settings.AntiSpam.SpamDeleteThreshold = 100; _application.Settings.AntiSpam.AddHeaderReason = true; _application.Settings.AntiSpam.AddHeaderSpam = true; _application.Settings.AntiSpam.PrependSubject = true; _application.Settings.AntiSpam.PrependSubjectText = "ThisIsSpam"; _application.Settings.AntiSpam.CheckHostInHelo = true; _application.Settings.AntiSpam.CheckHostInHeloScore = 105; hMailServer.IncomingRelay incomingRelay = _application.Settings.IncomingRelays.Add(); incomingRelay.LowerIP = "1.2.1.2"; incomingRelay.UpperIP = "1.2.1.3"; incomingRelay.Name = "Test"; incomingRelay.Save(); List <string> messages = new List <string>(); string message = "Received: from example.com (example.com [1.2.1.2]) by mail.host.edu\r\n" + "Received: from mail.hmailserver.com (mail.hmailserver.com [" + Utilities.GethMailServerCOMIPaddress() + "]) by mail.host.edu\r\n" + "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "Should be blocked by SPF."; messages.Add(message); int port = 1110; POP3Server pop3Server = new POP3Server(1, port, messages); pop3Server.StartListen(); hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.FetchAccount fa = account.FetchAccounts.Add(); fa.Enabled = true; fa.MinutesBetweenFetch = 10; fa.Name = "Test"; fa.Username = "******"; fa.Password = "******"; fa.UseSSL = false; fa.ServerAddress = "localhost"; fa.Port = port; fa.ProcessMIMERecipients = false; fa.DaysToKeepMessages = 0; fa.UseAntiSpam = true; fa.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); POP3Simulator.AssertMessageCount(account.Address, "test", 1); }
public void TestImportOfMessageIntoOtherFolder() { string @messageText = "From: [email protected]\r\n" + "\r\n" + "Test\r\n"; hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); account.IMAPFolders.Add("Woho"); string domainPath = Path.Combine(_application.Settings.Directories.DataDirectory, "test.com"); string accountPath = Path.Combine(domainPath, "test"); Directory.CreateDirectory(accountPath); string fileName = Path.Combine(accountPath, "something.eml"); File.WriteAllText(fileName, messageText); Assert.IsTrue(_application.Utilities.ImportMessageFromFileToIMAPFolder(fileName, account.ID, "Woho")); POP3Simulator.AssertMessageCount("*****@*****.**", "test", 0); IMAPSimulator sim = new IMAPSimulator(); sim.ConnectAndLogon("*****@*****.**", "test"); Assert.AreEqual(1, sim.GetMessageCount("Woho")); sim.Disconnect(); }
public void TestRetrievalOfMessageInDeletedFolder() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); string deletedMessageText = _settings.ServerMessages.get_ItemByName("MESSAGE_FILE_MISSING").Text; hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); hMailServer.IMAPFolder inbox = account.IMAPFolders.get_ItemByName("Inbox");; Utilities.AssertMessageExistsInFolder(inbox, 1); hMailServer.Message message = inbox.Messages[0]; DirectoryInfo dir = new DirectoryInfo(Path.GetFullPath(message.Filename)); DirectoryInfo parent = dir.Parent.Parent.Parent; parent.Delete(true); string text = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(text.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename))); Utilities.AssertReportedError(); }
public void TestReplaceInvalidPathWithCorrectPath() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test message", "Test body"); hMailServer.IMAPFolder folder = account.IMAPFolders.get_ItemByName("Inbox"); Utilities.AssertMessageExistsInFolder(folder, 1); hMailServer.Message message = account.IMAPFolders.get_ItemByName("Inbox").Messages[0]; string filename = message.Filename; // Now nothing should happen here. Assert.IsTrue(_application.Utilities.ImportMessageFromFile(filename, account.ID)); Assert.IsTrue(File.Exists(filename)); string sql = string.Format("update hm_messages set messagefilename = '{0}' where messageid = {1}", Utilities.Escape(message.Filename), message.ID); SingletonProvider <Utilities> .Instance.GetApp().Database.ExecuteSQL(sql); // Now the path should be replaced. Assert.IsTrue(_application.Utilities.ImportMessageFromFile(message.Filename, account.ID)); // Now nothing should happen. Assert.IsTrue(_application.Utilities.ImportMessageFromFile(message.Filename, account.ID)); Assert.IsTrue(File.Exists(message.Filename)); string content = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(content.Contains("Test message")); }
public void TestAutoReplyCombinedWithForwarding() { // 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.VacationMessageIsOn = true; oAccount2.VacationMessage = "I'm on vacation"; oAccount2.VacationSubject = "Out of office!"; oAccount2.ForwardAddress = oAccount3.Address; oAccount2.ForwardEnabled = true; oAccount2.ForwardKeepOriginal = true; oAccount2.Save(); // Send a message... SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body"); SingletonProvider <Utilities> .Instance.GetApp().SubmitEMail(); Utilities.AssertRecipientsInDeliveryQueue(0); // Wait for the auto-reply. POP3Simulator.AssertMessageCount(oAccount1.Address, "test", 1); POP3Simulator.AssertMessageCount(oAccount2.Address, "test", 1); POP3Simulator.AssertMessageCount(oAccount3.Address, "test", 1); }
public void TestForwardingAndDelete() { // 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"); // Set up account 1 to forward to account2. oAccount1.ForwardEnabled = true; oAccount1.ForwardAddress = "*****@*****.**"; oAccount1.ForwardKeepOriginal = false; oAccount1.Save(); // Send 2 messages to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.Send("*****@*****.**", "*****@*****.**", "INBOX", "POP3 test message"); Utilities.AssertRecipientsInDeliveryQueue(0); POP3Simulator.AssertMessageCount(oAccount2.Address, "test", 1); string domainDir = Path.Combine(_settings.Directories.DataDirectory, "test.com"); string userDir = Path.Combine(domainDir, "Forward1"); string[] dirs = Directory.GetDirectories(userDir); foreach (string dir in dirs) { string[] files = Directory.GetFiles(dir); Assert.AreEqual(0, files.Length); } }
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 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 MultiThread() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain.Accounts, "*****@*****.**", "test"); int threadCount = 5; _threadedMessageCount = 100; int totalMessageCount = threadCount * _threadedMessageCount; List <Thread> threads = new List <Thread>(); for (int thread = 0; thread < threadCount; thread++) { Thread t = new Thread(new ThreadStart(SendMessageThread)); threads.Add(t); t.Start(); } foreach (Thread t in threads) { t.Join(); } POP3Simulator.AssertMessageCount(account.Address, "test", totalMessageCount); for (int i = 0; i < totalMessageCount; i++) { string content = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(content.Contains("X-Spam-Status"), content); } }
public void TestMissingMXRecord() { 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.SpamDeleteThreshold = 1; _antiSpam.UseMXChecks = true; _antiSpam.UseMXChecksScore = 2; // Send a messages to this account. SMTPClientSimulator 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; POP3Simulator.AssertMessageCount(oAccount1.Address, "test", 1); }
public void TestEnabled() { 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(); // Enable SURBL. hMailServer.SURBLServer oSURBLServer = _antiSpam.SURBLServers[0]; oSURBLServer.Active = true; oSURBLServer.Score = 5; oSURBLServer.Save(); // Send a messages to this account. Assert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "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 detected as spam again. Assert.IsFalse(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); POP3Simulator.AssertMessageCount("*****@*****.**", "test", 1); }
public void TestSURBLCorrectNegative() { 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. Assert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "SURBL-Match", "This is a test message without a SURBL url: -> http://www.youtube.com/ <-")); string sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.Contains("X-hMailServer-Spam")) { throw new Exception("Non-spam message detected as spam"); } oSURBLServer.Active = false; oSURBLServer.Save(); }
public void TestSPFViaIncomingRelay() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); // Create a test account // Fetch the default domain ; hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); _antiSpam.SpamMarkThreshold = 1; _antiSpam.SpamDeleteThreshold = 100; _antiSpam.AddHeaderReason = true; _antiSpam.AddHeaderSpam = true; _antiSpam.PrependSubject = true; _antiSpam.PrependSubjectText = "ThisIsSpam"; // Enable SPF _antiSpam.UseSPF = true; _antiSpam.UseSPFScore = 5; string message = @"Received: from openspf.org ([76.79.20.184]) by Someone ; Mon, 29 Dec 2008 13:42:55 +0100\r\n" + "Message-ID: <5F90152F-DAC5-43CF-B553-FCF9302F6E0C@WORK>\r\n" + "From: [email protected]\r\n" + "To: [email protected]\r\n" + "\r\n" + "This is a test message.\r\n"; // Send a messages to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.SendRaw("*****@*****.**", oAccount1.Address, message); string sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsTrue(sMessageContents.Contains("X-hMailServer-Spam"), sMessageContents); // Add a forwarding relay pointing at localhost, so that the message will appear to be // properly forwarded. hMailServer.IncomingRelays incomingRelays = _settings.IncomingRelays; Assert.AreEqual(0, incomingRelays.Count); hMailServer.IncomingRelay incomingRelay = incomingRelays.Add(); incomingRelay.Name = "Localhost"; incomingRelay.LowerIP = "127.0.0.1"; incomingRelay.UpperIP = "127.0.0.1"; incomingRelay.Save(); oSMTP.SendRaw("*****@*****.**", oAccount1.Address, message); sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsFalse(sMessageContents.Contains("X-hMailServer-Spam"), sMessageContents); // change so that the forwarding relay no longer covers the IP. incomingRelay.LowerIP = "1.1.1.1"; incomingRelay.UpperIP = "1.1.1.1"; incomingRelay.Save(); oSMTP.SendRaw("*****@*****.**", oAccount1.Address, message); sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsTrue(sMessageContents.Contains("X-hMailServer-Spam"), sMessageContents); }
public void TestPOP3Server() { POP3Simulator sim = new POP3Simulator(); sim.ConnectAndLogon(GetUsername(), GetPassword()); EnsureNoPassword(); }
static void Main(string[] args) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); // Determine message count POP3Simulator pop3sim = new POP3Simulator(); int count = pop3sim.GetMessageCount("*****@*****.**", "test"); // Fetch them.. pop3sim.ConnectAndLogon("*****@*****.**", "test"); for (int i = 1; i <= count; i++) { pop3sim.RETR(i); } for (int i = 1; i <= count; i++) { pop3sim.DELE(i); } pop3sim.QUIT(); System.Threading.Thread.Sleep(1000 * 60 * 60); stopwatch.Stop(); Console.WriteLine("Passed time: " + stopwatch.Elapsed.TotalSeconds.ToString()); }
public void TestErrorOnMailFrom() { 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.MailFromResult = 561; server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can conenct to localhost. AddRoutePointingAtLocalhost(5, 250, false); // 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 bounceMessage = POP3Simulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(bounceMessage.Contains("MAIL FROM:<*****@*****.**>")); Assert.IsTrue(bounceMessage.Contains("Remote server replied: 561")); }
public void TestPermanentFailure() { Assert.AreEqual(0, _status.UndeliveredMessages.Length); Dictionary <string, int> deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 542; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. AddRoutePointingAtLocalhost(5, 250, false); // 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(); Assert.IsFalse(server.Conversation.Contains("\r\nDATA\r\n")); Utilities.AssertRecipientsInDeliveryQueue(0); string bounce = POP3Simulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(bounce.Contains("Remote server replied: 542 [email protected]")); }
public void TestMultipleHostsTemporaryFailure() { Assert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... Dictionary <string, int> deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; deliveryResults["*****@*****.**"] = 250; deliveryResults["*****@*****.**"] = 499; SMTPServerSimulator server = new SMTPServerSimulator(2, 250); server.AddRecipientResult(deliveryResults); server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. hMailServer.Route route = AddRoutePointingAtLocalhostMultipleHosts(2); // Send message to this route. SMTPClientSimulator smtp = new SMTPClientSimulator(); List <string> recipients = new List <string>(); recipients.Add("*****@*****.**"); recipients.Add("*****@*****.**"); recipients.Add("*****@*****.**"); if (!smtp.Send("*****@*****.**", recipients, "Test", "Test message")) { Assert.Fail("Delivery failed"); } // Wait for the client to disconnect. server.WaitForCompletion(); Utilities.AssertRecipientsInDeliveryQueue(1); // Check so that only user 3 remains in the queue. Assert.AreEqual(-1, _status.UndeliveredMessages.IndexOf("*****@*****.**")); Assert.AreEqual(-1, _status.UndeliveredMessages.IndexOf("*****@*****.**")); Assert.AreNotEqual(-1, _status.UndeliveredMessages.IndexOf("*****@*****.**")); server = new SMTPServerSimulator(2, 250); server.AddRecipientResult(deliveryResults); server.AddRecipientResult(deliveryResults); server.StartListen(); Utilities.AssertRecipientsInDeliveryQueue(0, true); server.WaitForCompletion(); string bounceMessage = POP3Simulator.AssertGetFirstMessageText("*****@*****.**", "test"); Assert.IsFalse(bounceMessage.Contains("*****@*****.**")); Assert.IsFalse(bounceMessage.Contains("*****@*****.**")); Assert.IsTrue(bounceMessage.Contains("*****@*****.**")); Assert.IsTrue(bounceMessage.Contains("499 [email protected]")); Assert.IsTrue(bounceMessage.Contains("Tried 2 time(s)")); }
public void TestDeliverToMyselfOnLocalPort() { Assert.AreEqual(0, _status.UndeliveredMessages.Length); // Add a route so we can conenct to localhost. AddRoutePointingAtLocalhost(1, 25, false); // Send message to this route. SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "subject", "body"); for (int i = 0; i < 40; i++) { string s = _status.UndeliveredMessages; if (s.Contains("\t\[email protected]")) { break; } Thread.Sleep(250); } // Wait for the bounce message to be delivered. Utilities.AssertRecipientsInDeliveryQueue(0, true); string message = POP3Simulator.AssertGetFirstMessageText("*****@*****.**", "test"); Assert.IsTrue(message.Contains("this would mean connecting to myself.")); }
public void TestRETR() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody1"); POP3Simulator.AssertMessageCount(account.Address, "test", 1); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody2"); POP3Simulator.AssertMessageCount(account.Address, "test", 2); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody3"); POP3Simulator.AssertMessageCount(account.Address, "test", 3); POP3Simulator sim = new POP3Simulator(); sim.ConnectAndLogon(account.Address, "test"); string result = sim.RETR(1); Assert.IsTrue(result.Contains("TestBody1"), result); result = sim.RETR(2); Assert.IsTrue(result.Contains("TestBody2"), result); result = sim.RETR(3); Assert.IsTrue(result.Contains("TestBody3"), result); Assert.IsFalse(result.Contains(".\r\n.")); }
public void TestNotificationOnPOP3Deletion() { _settings.IMAPIdleEnabled = true; hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Message 1", "Body 1"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Message 1", "Body 1"); POP3Simulator.AssertMessageCount(account.Address, "test", 2); IMAPSimulator imapSimulator = new IMAPSimulator(); string sWelcomeMessage = imapSimulator.Connect(); Assert.IsTrue(imapSimulator.Logon("*****@*****.**", "test")); Assert.IsTrue(imapSimulator.SelectFolder("INBOX")); Assert.IsTrue(imapSimulator.StartIdle()); POP3Simulator sim = new POP3Simulator(); Assert.IsTrue(sim.ConnectAndLogon(account.Address, "test")); Assert.IsTrue(sim.DELE(1)); sim.QUIT(); Assert.IsTrue(imapSimulator.AssertPendingDataExists()); string data = imapSimulator.Receive(); Assert.IsTrue(data.Contains("* 1 EXPUNGE")); Assert.IsFalse(imapSimulator.GetPendingDataExists()); }
public void TestSendToMultipleAccounts() { hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp(); 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"); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); List<string> lstRecipients = new List<string>(); lstRecipients.Add("*****@*****.**"); lstRecipients.Add("*****@*****.**"); lstRecipients.Add("*****@*****.**"); string sBody = "Test of sending same email to multiple accounts."; oSMTP.Send(oAccount1.Address, lstRecipients, "Multi test", sBody); POP3Simulator oPOP3 = new POP3Simulator(); string sMessageData = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageData.IndexOf(sBody) < 0) throw new Exception("E-mail not found"); sMessageData = POP3Simulator.AssertGetFirstMessageText(oAccount2.Address, "test"); if (sMessageData.IndexOf(sBody) < 0) throw new Exception("E-mail not found"); sMessageData = POP3Simulator.AssertGetFirstMessageText(oAccount3.Address, "test"); if (sMessageData.IndexOf(sBody) < 0) throw new Exception("E-mail not found"); }
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(); }
public void TestMessageScoreNotMerged() { // Send a messages to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); POP3Simulator oPOP3 = new POP3Simulator(); oSMTP.Send(account.Address, account.Address, "SA test", "This is a test message with spam.\r\n XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X."); string sMessageContents = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); int scoreStart = sMessageContents.IndexOf("X-hMailServer-Reason-Score"); Assert.AreNotSame(0, scoreStart); scoreStart = sMessageContents.IndexOf(":", scoreStart) +2; int scoreEnd = sMessageContents.IndexOf("\r\n", scoreStart); int scoreLength = scoreEnd - scoreStart; string score = sMessageContents.Substring(scoreStart, scoreLength); double scoreValue = Convert.ToDouble(score); Assert.Less(scoreValue, 10); }
public void TestDomainSignature() { POP3Simulator oPOP3 = new POP3Simulator(); domain.SignatureEnabled = true; domain.AddSignaturesToLocalMail = true; hMailServer.Account oAccount1 = SingletonProvider<Utilities>.Instance.AddAccount(domain, "*****@*****.**", "test"); oAccount1.SignatureEnabled = true; oAccount1.SignaturePlainText = "PlainTextSignature"; oAccount1.Save(); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); string sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.IndexOf("PlainTextSignature") <= 0) throw new Exception("Did not find signature"); domain.SignatureEnabled = true; domain.SignaturePlainText = "DomainSignature"; domain.SignatureMethod = hMailServer.eDomainSignatureMethod.eSMAppendToAccountSignature; domain.Save(); oSMTP.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.IndexOf("PlainTextSignature") <= 0 || sMessageContents.IndexOf("DomainSignature") <= 0) throw new Exception("Did not find signature"); domain.SignatureEnabled = true; domain.SignaturePlainText = "DomainSignature"; domain.SignatureMethod = hMailServer.eDomainSignatureMethod.eSMOverwriteAccountSignature; domain.Save(); oSMTP.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.IndexOf("PlainTextSignature") >= 0 || sMessageContents.IndexOf("DomainSignature") <= 0) throw new Exception("Did not find signature"); domain.SignatureEnabled = true; domain.SignaturePlainText = "DomainSignature"; domain.SignatureMethod = hMailServer.eDomainSignatureMethod.eSMSetIfNotSpecifiedInAccount; domain.Save(); oSMTP.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.IndexOf("DomainSignature") >= 0) throw new Exception("Found incorrect signature."); domain.SignatureEnabled = true; domain.SignaturePlainText = "DomainSignature"; domain.SignatureMethod = hMailServer.eDomainSignatureMethod.eSMSetIfNotSpecifiedInAccount; domain.Save(); oAccount1.SignaturePlainText = ""; oAccount1.Save(); oSMTP.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.IndexOf("DomainSignature") <= 0) throw new Exception("Found incorrect signature."); domain.AddSignaturesToLocalMail = false; domain.Save(); oAccount1.SignaturePlainText = "PlainTextSignature"; oAccount1.Save(); oSMTP.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.IndexOf("PlainTextSignature") > 0) throw new Exception("Found incorrect signature."); domain.AddSignaturesToLocalMail = true; domain.Save(); oSMTP.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.IndexOf("PlainTextSignature") <= 0) throw new Exception("Found incorrect signature."); }
public void TestAutoReplySubject() { // 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 = "Auto-Reply: %SUBJECT%"; oAccount2.Save(); // Send 1 message to this account SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body"); // Wait a second to be sure that the message // are delivered. // Check using POP3 that 2 messages exists. POP3Simulator oPOP3 = new POP3Simulator(); POP3Simulator.AssertMessageCount(oAccount1.Address, "test", 1); string s = oPOP3.GetFirstMessageText(oAccount1.Address, "test"); if (s.IndexOf("Subject: Auto-Reply: Test message") < 0) throw new Exception("ERROR - Auto reply subject not set properly."); }