public void TestSPFWithDebugLogging() { Application application = SingletonProvider <TestSetup> .Instance.GetApp(); string debugLog = _settings.Logging.CurrentDefaultLog; CustomAsserts.AssertDeleteFile(debugLog); // Create a test account // Fetch the default domain Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Disallow incorrect line endings. _antiSpam.SpamMarkThreshold = 1; _antiSpam.SpamDeleteThreshold = 100; _antiSpam.AddHeaderReason = true; _antiSpam.AddHeaderSpam = true; _antiSpam.PrependSubject = true; _antiSpam.PrependSubjectText = "ThisIsSpam"; // Enable SPF _antiSpam.UseSPF = true; _antiSpam.UseSPFScore = 12; // Send a messages to this account. var smtpClientSimulator = new SmtpClientSimulator(); smtpClientSimulator.Send("*****@*****.**", oAccount1.Address, "SPF test", "This is a test message."); string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (!sMessageContents.Contains("X-hMailServer-Spam")) { throw new Exception("Spam message not detected as spam"); } // Check that it has been logged. string contents = TestSetup.ReadExistingTextFile(debugLog); Assert.IsTrue(contents.Contains("Total spam score: 12")); Assert.IsTrue(contents.Contains("Spam test: SpamTestSPF, Score: 12")); CustomAsserts.AssertDeleteFile(debugLog); }
public void TestPOP3Client() { var messages = new List <string>(); string message = "From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!"; messages.Add(message); int port = TestSetup.GetNextFreePort(); using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); FetchAccount fa = account.FetchAccounts.Add(); fa.Enabled = true; fa.MinutesBetweenFetch = 10; fa.Name = "Test"; fa.Username = GetUsername(); fa.Password = GetPassword(); fa.UseSSL = false; fa.ServerAddress = "localhost"; fa.Port = port; fa.ProcessMIMERecipients = false; fa.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); string downloadedMessage = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(downloadedMessage.Contains(message)); EnsureNoPassword(); } }
public void TestMissingCipherInfoInReceivedHeader() { try { var smtpClientSimulator = new SmtpClientSimulator(false, 25); string errorMessage; smtpClientSimulator.Send(false, _account.Address, "test", _account.Address, _account.Address, "Test", "test", out errorMessage); var message = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsFalse(message.Contains("cipher\r\n")); } catch (Exception e) { Assert.Fail(e.ToString()); } }
public void TestESMTPSAInHeader() { try { var smtpClientSimulator = new SmtpClientSimulator(false, 25002); string errorMessage; smtpClientSimulator.Send(true, _account.Address, "test", _account.Address, _account.Address, "Test", "test", out errorMessage); var message = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(message.Contains("ESMTPSA\r\n")); } catch (Exception e) { Assert.Fail(e.ToString()); } }
public void TestAccountSignatureMacro() { _domain.SignatureEnabled = true; _domain.AddSignaturesToLocalMail = true; _account.PersonFirstName = "Martin"; _account.PersonLastName = "Knafve"; _account.SignatureEnabled = true; _account.SignaturePlainText = "Regards %User.FirstName% %User.Lastname%"; _account.Save(); SmtpClientSimulator.StaticSend(_account.Address, _account.Address, "Test of signature, 2", "Test of signature - Body"); string sMessageData = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(sMessageData.Contains("Regards Martin Knafve")); }
public void ConfirmSingleReturnPathAfterRuleForward() { // Create a test account // Fetch the default _domain Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Account oAccount2 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Set up a rule to trash the message. Rule oRule = oAccount1.Rules.Add(); oRule.Name = "Criteria test"; oRule.Active = true; RuleCriteria oRuleCriteria = oRule.Criterias.Add(); oRuleCriteria.UsePredefined = true; oRuleCriteria.PredefinedField = eRulePredefinedField.eFTMessageSize; oRuleCriteria.MatchType = eRuleMatchType.eMTGreaterThan; oRuleCriteria.MatchValue = "0"; oRuleCriteria.Save(); // Add action RuleAction oRuleAction = oRule.Actions.Add(); oRuleAction.Type = eRuleActionType.eRAForwardEmail; oRuleAction.To = oAccount2.Address; oRuleAction.Save(); // Save the rule in the database oRule.Save(); // Make sure that that a forward is made if no rule is set up. SmtpClientSimulator.StaticSend("*****@*****.**", oAccount1.Address, "Test message", "This is the body"); Pop3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); _application.SubmitEMail(); // Wait for the auto-reply. string text = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount2.Address, "test"); Assert.IsTrue(text.Contains("Return-Path: [email protected]")); Assert.IsFalse(text.Contains("Return-Path: [email protected]")); Assert.IsFalse(text.Contains("Return-Path: [email protected]")); }
public void TestDNSBlackList() { DNSBlackLists dnsBlackLists = SingletonProvider <TestSetup> .Instance.GetApp().Settings.AntiSpam.DNSBlackLists; DNSBlackList dnsBlackList = dnsBlackLists.Add(); dnsBlackList.DNSHost = "zen.spamhaus.org"; dnsBlackList.RejectMessage = "srv1"; dnsBlackList.Score = 5; dnsBlackList.Active = true; dnsBlackList.Save(); dnsBlackList = dnsBlackLists.Add(); dnsBlackList.DNSHost = "bl.spamcop.net"; dnsBlackList.RejectMessage = "srv2"; dnsBlackList.Score = 5; dnsBlackList.Active = false; dnsBlackList.Save(); dnsBlackList = dnsBlackLists.Add(); dnsBlackList.DNSHost = "dnsbl.njabl.org"; dnsBlackList.RejectMessage = "srv3"; dnsBlackList.Score = 5; dnsBlackList.Active = true; dnsBlackList.Save(); Application application = SingletonProvider <TestSetup> .Instance.GetApp(); _antiSpam.SpamMarkThreshold = 1; _antiSpam.SpamDeleteThreshold = 100; Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); LogHandler.DeleteCurrentDefaultLog(); SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody"); Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); string result = LogHandler.ReadCurrentDefaultLog(); Assert.IsTrue(result.Contains(".zen.spamhaus.org, 0 addresses found: (none), Match: False"), result); Assert.IsTrue(result.Contains(".dnsbl.njabl.org, 0 addresses found: (none), Match: False"), result); Assert.IsFalse(result.Contains(".bl.spamcop.net, 0 addresses found:"), result); }
public void TestSendToMultipleAccounts() { Application application = SingletonProvider <TestSetup> .Instance.GetApp(); Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Account oAccount2 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Account oAccount3 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var smtpClientSimulator = new SmtpClientSimulator(); var lstRecipients = new List <string>(); lstRecipients.Add("*****@*****.**"); lstRecipients.Add("*****@*****.**"); lstRecipients.Add("*****@*****.**"); string sBody = "Test of sending same email to multiple accounts."; smtpClientSimulator.Send(oAccount1.Address, lstRecipients, "Multi test", sBody); var pop3ClientSimulator = new Pop3ClientSimulator(); string sMessageData = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageData.IndexOf(sBody) < 0) { throw new Exception("E-mail not found"); } sMessageData = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount2.Address, "test"); if (sMessageData.IndexOf(sBody) < 0) { throw new Exception("E-mail not found"); } sMessageData = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount3.Address, "test"); if (sMessageData.IndexOf(sBody) < 0) { throw new Exception("E-mail not found"); } }
public void TestRenameDomainWithMessages() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); account.ForwardAddress = "*****@*****.**"; account.Save(); string messageBody = Guid.NewGuid().ToString(); SmtpClientSimulator.StaticSend(account.Address, account.Address, "Subj", messageBody); Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); _domain.Name = "example.com"; _domain.Save(); string messageText = Pop3ClientSimulator.AssertGetFirstMessageText("*****@*****.**", "test"); Assert.IsTrue(messageText.Contains(messageBody), messageText); }
public void TestSignatureMacroLocalDomainNonExistantAccount() { _domain.SignatureEnabled = true; _domain.SignaturePlainText = "MyDomainSignature %User.FirstName%"; _domain.AddSignaturesToLocalMail = true; _domain.Save(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); account.PersonFirstName = "Martin"; var smtpClientSimulator = new SmtpClientSimulator(); smtpClientSimulator.Send("nonexistant@" + _domain.Name, account.Address, "SignatureTest", "SignaturerTestBody"); string messageData = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(messageData.Contains("%User.FirstName%")); }
public void TestMailCreationPlainText() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var message = new hMailServer.Message(); message.AddRecipient("", account.Address); message.Body = "Hello"; message.Save(); string messageText = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); int headerEnd = messageText.IndexOf("\r\n\r\n"); string header = messageText.Substring(0, headerEnd); Assert.IsTrue(header.Contains("Content-Type: text/plain; charset=\"utf-8\"")); Assert.IsTrue(header.Contains("Content-Transfer-Encoding: quoted-printable")); Assert.IsTrue(messageText.Contains("Hello")); }
public void BounceMessageShouldContainSubjectAndDate() { Account senderAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Account recipientAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); recipientAccount.MaxSize = 1; recipientAccount.Save(); // Make sure that no bounce is sent. SmtpClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "MySubject", "Test"); Pop3ClientSimulator.AssertGetFirstMessageText(recipientAccount.Address, "test"); // Build a 2MB string. var builder = new StringBuilder(); for (int i = 0; i < 11000; i++) { builder.Append( "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\n"); } string text = builder.ToString(); SmtpClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "Test subject", text); // Make sure the recipient did not receive it. CustomAsserts.AssertRecipientsInDeliveryQueue(0); Pop3ClientSimulator.AssertMessageCount(recipientAccount.Address, "test", 0); CustomAsserts.AssertFilesInUserDirectory(recipientAccount, 0); // Make sure it bounced. string content = Pop3ClientSimulator.AssertGetFirstMessageText(senderAccount.Address, "test"); Assert.IsTrue(content.Contains("Inbox is full")); Assert.IsTrue(content.Contains("Subject: Test subject")); // Make sure body contains year. int bodyStartPos = content.IndexOf("\r\n\r\n"); int yearPos = content.IndexOf(DateTime.Now.Year.ToString(), bodyStartPos); Assert.IsTrue(yearPos >= 0); }
public void TestIncorrectPort() { var smtpClientSimulator = new SmtpClientSimulator(); _settings.AntiSpam.SpamAssassinEnabled = true; _settings.AntiSpam.SpamAssassinHost = "localhost"; // <- mispelled _settings.AntiSpam.SpamAssassinPort = 12345; smtpClientSimulator.Send(account.Address, account.Address, "SA test", "This is a test message."); string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); if (sMessageContents.Contains("X-Spam-Status")) { _settings.AntiSpam.SpamAssassinEnabled = false; throw new Exception("Spam assassin not run"); } CustomAsserts.AssertReportedError("The SpamAssassin tests did not complete. Please confirm that the configuration (host name and port) is valid and that SpamAssassin is running."); }
public void TestSPF() { Application application = SingletonProvider <TestSetup> .Instance.GetApp(); // Create a test account // Fetch the default domain Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Disallow incorrect line endings. _antiSpam.SpamMarkThreshold = 1; _antiSpam.SpamDeleteThreshold = 100; _antiSpam.AddHeaderReason = true; _antiSpam.AddHeaderSpam = true; _antiSpam.PrependSubject = true; _antiSpam.PrependSubjectText = "ThisIsSpam"; // Enable SPF _antiSpam.UseSPF = true; _antiSpam.UseSPFScore = 5; // Send a messages to this account. var smtpClientSimulator = new SmtpClientSimulator(); smtpClientSimulator.Send("*****@*****.**", oAccount1.Address, "SPF test", "This is a test message."); string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (!sMessageContents.Contains("X-hMailServer-Spam")) { throw new Exception("Spam message not detected as spam"); } _antiSpam.UseSPF = false; smtpClientSimulator.Send("*****@*****.**", oAccount1.Address, "SPF test", "This is a test message."); sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.Contains("X-hMailServer-Spam")) { throw new Exception("Non-spam message detected as spam"); } }
public void TestAddTextDuringSendingAttachment() { Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to the account. var oMessage = new hMailServer.Message(); Assert.AreEqual(0, oMessage.State); Scripting scripting = SingletonProvider <TestSetup> .Instance.GetApp().Settings.Scripting; string signature = "MySignature"; string script = "Sub OnAcceptMessage(oClient, oMessage) " + Environment.NewLine + " oMessage.Body = oMessage.Body & \"" + signature + "\" " + Environment.NewLine + " oMessage.Save() " + Environment.NewLine + "End Sub" + Environment.NewLine + Environment.NewLine; File.WriteAllText(scripting.CurrentScriptFile, script); scripting.Enabled = true; scripting.Reload(); Assembly a = Assembly.GetExecutingAssembly(); var mail = new MailMessage(); mail.From = new MailAddress("*****@*****.**"); mail.To.Add("*****@*****.**"); mail.Subject = "Automatiskt servertest"; mail.Body = "Detta är ett automatiskt test av epostservern."; mail.BodyEncoding = Encoding.GetEncoding(1252); mail.SubjectEncoding = Encoding.GetEncoding(1252); mail.Attachments.Add(new Attachment(a.Location)); var oClient = new SmtpClient("localhost", 25); oClient.Send(mail); // Check that the message exists string message = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsNotEmpty(message, message); Assert.IsTrue(message.Contains(signature), message); }
public void SurblTestRealWorldBody1() { LogHandler.DeleteCurrentDefaultLog(); // Create a test account // Fetch the default domain Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Disallow incorrect line endings. _antiSpam.SpamMarkThreshold = 1; _antiSpam.SpamDeleteThreshold = 100; _antiSpam.AddHeaderReason = true; _antiSpam.AddHeaderSpam = true; _antiSpam.PrependSubject = true; _antiSpam.PrependSubjectText = "ThisIsSpam"; // Enable SURBL. SURBLServer oSURBLServer = _antiSpam.SURBLServers[0]; oSURBLServer.Active = true; oSURBLServer.Score = 5; oSURBLServer.Save(); // Send a messages to this account. var smtpClientSimulator = new SmtpClientSimulator(); smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "SURBL-Match", TestResources.SecuniaBody1); string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsFalse(sMessageContents.Contains("X-hMailServer-Spam"), "Spam message not detected as spam"); oSURBLServer.Active = false; oSURBLServer.Save(); Assert.IsTrue(LogHandler.DefaultLogContains("SURBL: 2 unique addresses found.")); Assert.IsTrue(LogHandler.DefaultLogContains("SURBL: Found URL: secunia.com")); Assert.IsFalse(LogHandler.DefaultLogContains("SURBL: Found URL: ecunia.com")); Assert.IsTrue(LogHandler.DefaultLogContains("SURBL: Lookup: secunia.com.multi.surbl.org")); Assert.IsTrue(LogHandler.DefaultLogContains("SURBL: Lookup: ubuntu.com.multi.surbl.org")); }
public void TestGreyListingWithDomainAliases() { _antiSpam.GreyListingEnabled = false; Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var smtp = new SmtpClientSimulator(); var recipients = new List <string>(); recipients.Add(account1.Address); smtp.Send("*****@*****.**", recipients, "Test", "Body"); Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); _antiSpam.GreyListingEnabled = true; CustomAsserts.Throws <DeliveryFailedException>(() => smtp.Send("*****@*****.**", recipients, "Test", "Body")); _domain.AntiSpamEnableGreylisting = false; _domain.Save(); smtp.Send("*****@*****.**", recipients, "Test", "Body"); Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); DomainAlias da = _domain.DomainAliases.Add(); da.AliasName = "test2.com"; da.Save(); recipients = new List <string>(); recipients.Add("*****@*****.**"); smtp.Send("*****@*****.**", recipients, "Test", "Body"); Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); _domain.AntiSpamEnableGreylisting = true; _domain.Save(); CustomAsserts.Throws <DeliveryFailedException>(() => smtp.Send("*****@*****.**", recipients, "Test", "Body")); }
public void TestMessageScore() { // Send a messages to this account. var smtpClientSimulator = new SmtpClientSimulator(); smtpClientSimulator.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 = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); int scoreStart = sMessageContents.IndexOf("X-Spam-Status: Yes, score") + "X-Spam-Status: Yes, score".Length + 1; int scoreEnd = sMessageContents.IndexOf(".", scoreStart); int scoreLength = scoreEnd - scoreStart; string score = sMessageContents.Substring(scoreStart, scoreLength); double scoreValue = Convert.ToDouble(score); Assert.Greater(scoreValue, 500); }
public void TestUseCaseDeliveryFromPrimaryMXToBackupMX() { int smtpServerPort = TestSetup.GetNextFreePort(); Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false); route.TreatRecipientAsLocalDomain = true; route.TreatSenderAsLocalDomain = false; route.Save(); Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var smtpClientSimulator = new SmtpClientSimulator(); string result; smtpClientSimulator.Send("*****@*****.**", account1.Address, "Mail 1", "Mail 1", out result); string text = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); Assert.IsTrue(text.Contains("Mail 1")); }
public void TestFailureAfterReceivedHelloBanner() { _application.Settings.SMTPNoOfTries = 3; _application.Settings.SMTPMinutesBetweenTry = 60; Assert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... var deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.SimulatedError = SimulatedErrorType.DisconnectAfterSessionStart; server.StartListen(); // Add a route so we can connect to localhost. TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false); // Send message to this route. var smtp = new SmtpClientSimulator(); var recipients = new List <string>(); recipients.Add("*****@*****.**"); smtp.Send(_account.Address, recipients, "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); // Force the message to be bounced. CustomAsserts.AssertRecipientsInDeliveryQueue(0, true); string bounce = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(bounce.Contains("*****@*****.**")); Assert.IsTrue(bounce.Contains("Remote server closed connection.")); Assert.IsTrue(bounce.Contains("Tried 1 time(s)")); } }
public void TestSignature() { _domain.SignatureEnabled = true; _domain.AddSignaturesToLocalMail = true; _account.SignatureEnabled = true; var smtpClientSimulator = new SmtpClientSimulator(); smtpClientSimulator.Send(_account.Address, _account.Address, "Test of signature, 1", "Test of signature - Body"); string sMessageData = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); if (sMessageData.IndexOf("PlainTextSignature") > 0) { throw new Exception("Found exception which should not be there"); } _account.SignaturePlainText = "PlainTextSignature"; _account.Save(); smtpClientSimulator.Send(_account.Address, _account.Address, "Test of signature, 2", "Test of signature - Body"); sMessageData = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); if (sMessageData.IndexOf("PlainTextSignature") < 0) { throw new Exception("Did not find expected signature"); } // Turn off signature again _account.SignatureEnabled = false; _account.Save(); smtpClientSimulator.Send(_account.Address, _account.Address, "Test of signature, 2", "Test of signature - Body"); sMessageData = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); if (sMessageData.IndexOf("PlainTextSignature") > 0) { throw new Exception("Found signature even though there shouldn't be any"); } }
public void TestReplaceFullPathWithPartialPath() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test message", "Test body"); IMAPFolder folder = account.IMAPFolders.get_ItemByName("Inbox"); CustomAsserts.AssertFolderMessageCount(folder, 1); hMailServer.Message message = account.IMAPFolders.get_ItemByName("Inbox").Messages[0]; // Now nothing should happen. Assert.IsTrue(_application.Utilities.ImportMessageFromFile(message.Filename, account.ID)); // Move the message file to another folder. string domainPath = Path.Combine(_application.Settings.Directories.DataDirectory, _domain.Name); string accountPath = Path.Combine(domainPath, "test"); string fileName = Path.Combine(accountPath, "randomMail.eml"); File.Move(message.Filename, fileName); // Update the database with the 'invalid' path. string sql = string.Format("update hm_messages set messagefilename = '{0}' where messageid = {1}", TestSetup.Escape(fileName), message.ID); SingletonProvider <TestSetup> .Instance.GetApp().Database.ExecuteSQL(sql); Assert.IsTrue(File.Exists(fileName)); // Now the file should be moved to the correct path. Assert.IsTrue(_application.Utilities.ImportMessageFromFile(fileName, account.ID)); Assert.IsFalse(File.Exists(fileName)); // Now nothing should happen because the file is no longer there. Assert.IsFalse(_application.Utilities.ImportMessageFromFile(fileName, account.ID)); string content = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(content.Contains("Test message")); }
public void TestInvalidBodyHashMark() { _antiSpam.SpamDeleteThreshold = 1000; _antiSpam.SpamMarkThreshold = 5; _antiSpam.DKIMVerificationEnabled = true; _antiSpam.DKIMVerificationFailureScore = 6; string messageText = @"DKIM-Signature: v=1; a=rsa-sha1; c=simple; d=messiah.edu; h=from:to" + "\r\n" + " :subject:date; s=test3; [email protected]; bh=OW2otvzd7V2TO8"+ "\r\n" + " w056SjbYRFCa0=; b=Vfr8HgUlyVf1ZaRVMV8VJNSDXn7f1j2N/rFM4PPmYIC2GD"+ "\r\n" + " pSelCRrdA979Buuu/Mmx9FTWoZJBL+s5tafFM8bw=="+ "\r\n" + "Received: from x.y.test" + "\r\n" + " by example.net" + "\r\n" + " via TCP" + "\r\n" + " with ESMTP" + "\r\n" + " id ABC12345" + "\r\n" + " for <*****@*****.**>; 21 Nov 1997 10:05:43 -0600" + "\r\n" + "Received: from machine.example by x.y.test; 21 Nov 1997 10:01:22 -0600" + "\r\n" + "From: Jason Long <*****@*****.**>" + "\r\n" + "To: Nobody <*****@*****.**>" + "\r\n" + "Subject: dkim test (i= uses quoted-printable)" + "\r\n" + "Date: Wed, 9 Apr 2008 09:11:00 -0500" + "\r\n" + "" + "\r\n" + "Should pass." + "\r\n" + "" + "\r\n" + "This is a test" + "\r\n" + " More lines here" + "\r\n" + "" + "\r\n" + "Blah blah blah" + "\r\n" + "" + "\r\n" + "" + "\r\n" + "" + "\r\n" + "" + "\r\n"; Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SmtpClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText); string text = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); Assert.IsTrue(text.Contains("Rejected by DKIM. - (Score: 6)")); }
public void TestMailCreationHTMLAndPlainTextReverse() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var message = new hMailServer.Message(); message.AddRecipient("", account.Address); message.Body = "PlainTextBody"; message.HTMLBody = "HTMLBody"; message.Save(); string messageText = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); int headerEnd = messageText.IndexOf("\r\n\r\n"); string header = messageText.Substring(0, headerEnd); Assert.IsTrue(header.Contains("Content-Type: multipart/alternative")); Assert.IsFalse(header.Contains("Content-Transfer-Encoding: quoted-printable")); Assert.IsTrue(messageText.Contains("PlainTextBody")); Assert.IsTrue(messageText.Contains("HTMLBody")); }
public void TestGreyListingWhiteListWildcard() { _antiSpam.GreyListingEnabled = true; Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); GreyListingWhiteAddresses whiteAddresses = _antiSpam.GreyListingWhiteAddresses; GreyListingWhiteAddress whiteAddress = whiteAddresses.Add(); whiteAddress.IPAddress = "127.0.0.5"; whiteAddress.Save(); CustomAsserts.Throws <DeliveryFailedException>(() => SmtpClientSimulator.StaticSend("*****@*****.**", account.Address, "Test", "Test")); whiteAddress.IPAddress = "*"; whiteAddress.Save(); SmtpClientSimulator.StaticSend("*****@*****.**", account.Address, "Test", "Test"); Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); }
public void TestTwoBlockedAttachments() { var attachment1Name = Guid.NewGuid().ToString() + ".dll"; var attachment2Name = Guid.NewGuid().ToString() + ".dll"; var tempFile1 = Path.Combine(Path.GetTempPath(), attachment1Name); var tempFile2 = Path.Combine(Path.GetTempPath(), attachment2Name); File.WriteAllText(tempFile1, "A"); File.WriteAllText(tempFile2, "A"); try { using (var attachment1 = new System.Net.Mail.Attachment(tempFile1)) using (var attachment2 = new System.Net.Mail.Attachment(tempFile2)) { var mail = new MailMessage(); mail.From = new MailAddress("*****@*****.**"); mail.To.Add("*****@*****.**"); mail.Subject = "Test"; mail.Body = "Test"; mail.BodyEncoding = Encoding.GetEncoding(1252); mail.SubjectEncoding = Encoding.GetEncoding(1252); mail.Attachments.Add(attachment1); mail.Attachments.Add(attachment2); var smtpClient = new SmtpClient("localhost", 25); smtpClient.Send(mail); } // Check that the message exists string message = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(message.Contains(string.Format("The attachment {0} was blocked for delivery by the e-mail server.", attachment1Name))); Assert.IsTrue(message.Contains(string.Format("The attachment {0} was blocked for delivery by the e-mail server.", attachment2Name))); } finally { File.Delete(tempFile1); File.Delete(tempFile2); } }
public void TestAuthFailurePasswordInBounce() { Assert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... var deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.SimulatedError = SimulatedErrorType.ForceAuthenticationFailure; server.StartListen(); // Add a route so we can connect to localhost. Route route = TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false); route.RelayerRequiresAuth = true; route.RelayerAuthUsername = "******"; route.SetRelayerAuthPassword("MySecretPassword"); // Send message to this route. var smtp = new SmtpClientSimulator(); var recipients = new List <string>(); recipients.Add("*****@*****.**"); smtp.Send("*****@*****.**", recipients, "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); CustomAsserts.AssertRecipientsInDeliveryQueue(0); string messageText = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsFalse(messageText.Contains("MySecretPassword")); Assert.IsTrue(messageText.Contains("<Password removed>")); } }
public void TestSurblMultipleNegatives() { LogHandler.DeleteCurrentDefaultLog(); // Create a test account // Fetch the default domain Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Disallow incorrect line endings. _antiSpam.SpamMarkThreshold = 1; _antiSpam.SpamDeleteThreshold = 100; _antiSpam.AddHeaderReason = true; _antiSpam.AddHeaderSpam = true; _antiSpam.PrependSubject = true; _antiSpam.PrependSubjectText = "ThisIsSpam"; // Enable SURBL. SURBLServer oSURBLServer = _antiSpam.SURBLServers[0]; oSURBLServer.Active = true; oSURBLServer.Score = 5; oSURBLServer.Save(); // Send a messages to this account. var smtpClientSimulator = new SmtpClientSimulator(); smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "SURBL-Match", "Wrapped URL - <a href=3D\"http://test.example1fdafdsfds.com\">Test</a>\r\nWrapped URL - <a href=3D\"http://test.example2fdafdsfds.com\">Test</a>\r\nWrapped URL - <a href=3D\"http://test.example3fdafdsfds.com\">Test</a>\r\n"); string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsFalse(sMessageContents.Contains("X-hMailServer-Spam"), "Spam message not detected as spam"); oSURBLServer.Active = false; oSURBLServer.Save(); Assert.IsTrue(LogHandler.DefaultLogContains("SURBL: Lookup: example1fdafdsfds.com.multi.surbl.org")); Assert.IsTrue(LogHandler.DefaultLogContains("SURBL: Lookup: example2fdafdsfds.com.multi.surbl.org")); Assert.IsTrue(LogHandler.DefaultLogContains("SURBL: Lookup: example3fdafdsfds.com.multi.surbl.org")); }
public void TestOnErrorJScript() { Application app = SingletonProvider <TestSetup> .Instance.GetApp(); Scripting scripting = app.Settings.Scripting; scripting.Language = "JScript"; string script = "function OnError(iSeverity, iError, sSource, sDescription) {" + Environment.NewLine + " EventLog.Write('Severity: ' + iSeverity) " + Environment.NewLine + " EventLog.Write('Error: ' + iError) " + Environment.NewLine + " EventLog.Write('Source: ' + sSource) " + Environment.NewLine + " EventLog.Write('Description: ' + sDescription) " + Environment.NewLine + "}" + Environment.NewLine + Environment.NewLine; File.WriteAllText(scripting.CurrentScriptFile, script); scripting.Enabled = true; scripting.Reload(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); IMAPFolder inbox = account.IMAPFolders.get_ItemByName("Inbox"); string deletedMessageText = app.Settings.ServerMessages.get_ItemByName("MESSAGE_FILE_MISSING").Text; SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); CustomAsserts.AssertFolderMessageCount(inbox, 1); hMailServer.Message message = inbox.Messages[0]; File.Delete(message.Filename); string text = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(text.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename))); CustomAsserts.AssertReportedError("Message retrieval failed because message file"); string eventLogText = TestSetup.ReadExistingTextFile(app.Settings.Logging.CurrentEventLog); Assert.IsTrue(eventLogText.Contains("Description: Message retrieval failed")); }
public void TestAddTextDuringSending() { Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to the account. var oMessage = new hMailServer.Message(); Assert.AreEqual(0, oMessage.State); Scripting scripting = SingletonProvider <TestSetup> .Instance.GetApp().Settings.Scripting; string signature = "MySignature"; string script = "Sub OnAcceptMessage(oClient, oMessage) " + Environment.NewLine + " Call EventLog.Write(\"Subject:\" +oMessage.Subject)" + Environment.NewLine + " Call EventLog.Write(\"Date:\" +oMessage.Date)" + Environment.NewLine + " Call EventLog.Write(\"Body:\" +oMessage.Body)" + Environment.NewLine + " oMessage.Body = oMessage.Body & \"" + signature + "\" " + Environment.NewLine + " oMessage.Save() " + Environment.NewLine + "End Sub" + Environment.NewLine + Environment.NewLine; File.WriteAllText(scripting.CurrentScriptFile, script); scripting.Enabled = true; scripting.Reload(); Assert.IsEmpty(scripting.CheckSyntax()); // Send the message. var recipients = new List <string>(); recipients.Add("*****@*****.**"); SmtpClientSimulator.StaticSend("*****@*****.**", recipients, "Hej", "Välkommen till verkligheten"); // Check that the message exists string message = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsNotEmpty(message); Assert.IsTrue(message.Contains(signature)); Assert.Less(0, message.IndexOf("Hej")); }