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 SmtpRelayShouldConsolidateRecipients() { // Set up a server listening on port 250 which accepts email for [email protected] var deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; deliveryResults["*****@*****.**"] = 250; deliveryResults["*****@*****.**"] = 250; deliveryResults["*****@*****.**"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); using (var server = new SmtpServerSimulator(1, smtpServerPort)) { _application.Settings.SMTPRelayer = "localhost"; _application.Settings.SMTPRelayerPort = smtpServerPort; server.AddRecipientResult(deliveryResults); server.StartListen(); var smtpClient = new SmtpClientSimulator(); var recipients = new List <string>() { "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**" }; Account senderAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); smtpClient.Send(senderAccount.Address, recipients, "Test", "Test message"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); server.WaitForCompletion(); Assert.IsTrue(server.MessageData.Contains("Test message")); Assert.AreEqual(deliveryResults.Count, server.RcptTosReceived); } }
public async Task ExtractNavigationPoints_TocXHtmlExample2_ExtractsNavigation() { var doc = await XmlStructureFile.LoadFromTextAsync(string.Empty, TestResources.TocXHtmlExample2); var coverFile = TestItemFactory.CreateFileFromString("cover.xhtml"); var introFile = TestItemFactory.CreateFileFromString("intro.xhtml"); var testee = new XHtmlNavigationExtractor(); var result = testee.ExtractNavigationPoints(doc, new[] { coverFile, introFile }); var expected = new[] { new NavigationPoint("Cover", coverFile, null, 1, new NavigationPoint[0]), new NavigationPoint("INTRODUCTION", introFile, "intro", 2, new [] { new NavigationPoint("About", introFile, "lev1", 3, new NavigationPoint[0]), }), }; CustomAsserts.AssertNavigationPointsAreEqual(result, expected); }
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 TestSenderAsExternalDomainSendToLocalAccountFail() { int smtpServerPort = TestSetup.GetNextFreePort(); Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false); route.TreatSenderAsLocalDomain = false; route.Save(); SecurityRange range = SingletonProvider <TestSetup> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer"); range.RequireSMTPAuthExternalToLocal = true; range.Save(); Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var smtpClientSimulator = new SmtpClientSimulator(); string result; CustomAsserts.Throws <DeliveryFailedException>(() => smtpClientSimulator.Send("*****@*****.**", account1.Address, "Mail 1", "Mail 1", out result)); }
public void TestWithVirus() { _antiVirus.ClamAVEnabled = true; LogHandler.DeleteCurrentDefaultLog(); Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string firstPart = @"X5O!P%@AP[4\PZX54(P^)7CC)7}"; string secondPart = @"$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"; SmtpClientSimulator.StaticSend(account1.Address, account1.Address, "Mail 1", firstPart + secondPart); CustomAsserts.AssertRecipientsInDeliveryQueue(0); Pop3ClientSimulator.AssertMessageCount(account1.Address, "test", 0); string defaultLog = LogHandler.ReadCurrentDefaultLog(); Assert.IsTrue(defaultLog.Contains("Connecting to ClamAV")); Assert.IsTrue(defaultLog.Contains("Message deleted (contained virus Eicar-Test-Signature)")); }
public void RoutesShouldSupportWildcardDomain() { // Set up a server listening on port 250 which accepts email for [email protected] var deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route pointing at localhost Route route = _settings.Routes.Add(); route.DomainName = "*.example.com"; route.TargetSMTPHost = "localhost"; route.TargetSMTPPort = smtpServerPort; route.NumberOfTries = 1; route.MinutesBetweenTry = 5; route.TreatRecipientAsLocalDomain = true; route.TreatSenderAsLocalDomain = true; route.AllAddresses = true; route.Save(); // Make sure only the specific user is valid. RouteAddress routeAddress = route.Addresses.Add(); routeAddress.Address = "user@" + _domain.Name; routeAddress.Save(); var smtpClient = new SmtpClientSimulator(); smtpClient.Send("*****@*****.**", "*****@*****.**", "Test", "Test message"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); server.WaitForCompletion(); Assert.IsTrue(server.MessageData.Contains("Test message")); } }
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 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 TestSendViaSpamAssassin() { CustomAsserts.AssertSpamAssassinIsRunning(); SingletonProvider <TestSetup> .Instance.GetApp().Settings.AntiSpam.SpamAssassinEnabled = true; string dataDir = Path.Combine(SingletonProvider <TestSetup> .Instance.GetApp().Settings.Directories.DataDirectory, "test.com"); string accountDir = Path.Combine(dataDir, "test"); int memoryUsage = Shared.GetCurrentMemoryUsage(); int maxMemoryUsage = memoryUsage + 2; const int numberOfMessages = 100; var mail = new MailMessage(); mail.From = new MailAddress("*****@*****.**"); mail.To.Add("*****@*****.**"); mail.Subject = "Automatic server test"; mail.Body = "Automatic server test"; mail.BodyEncoding = Encoding.GetEncoding(1252); mail.SubjectEncoding = Encoding.GetEncoding(1252); for (int i = 1; i <= numberOfMessages; i++) { var oClient = new SmtpClient("localhost", 25); oClient.Send(mail); if (i % 5 == 0) { Shared.AssertLowMemoryUsage(maxMemoryUsage); TestTracer.WriteTraceInfo("{0}/{1}", i, numberOfMessages); } } WaitForFilesInFolder(accountDir, numberOfMessages); _domain.Delete(); }
public void RecipientNotInListShouldReturnError() { // Add a route pointing at localhost Route route = _settings.Routes.Add(); route.DomainName = "test.com"; route.TargetSMTPHost = "localhost"; route.TargetSMTPPort = 255; route.NumberOfTries = 1; route.MinutesBetweenTry = 5; route.TreatRecipientAsLocalDomain = true; route.TreatSenderAsLocalDomain = true; route.AllAddresses = false; // only to recipients in list. route.Save(); var smtpClient = new SmtpClientSimulator(); string resultMessage = ""; CustomAsserts.Throws <DeliveryFailedException>(() => smtpClient.Send("*****@*****.**", "*****@*****.**", "Test", "Test message", out resultMessage)); Assert.AreEqual("550 Recipient not in route list.", resultMessage); }
public void FailedDeliveriesDueToAuthErrorShouldBeLogged() { SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); IPAddress localAddress = TestSetup.GetLocalIpAddress(); var smtpClientSimulator = new SmtpClientSimulator(false, 25, localAddress); // Failed delivery from local to local. CustomAsserts.Throws <DeliveryFailedException>(() => smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1")); // Verify that the failed delivery is logged string contents = TestSetup.ReadExistingTextFile(_logging.CurrentAwstatsLog); CustomAsserts.AssertDeleteFile(_logging.CurrentAwstatsLog); string expectedString = string.Format("\[email protected]\[email protected]\t{0}\t127.0.0.1\tSMTP\t?\t530\t", localAddress); StringAssert.Contains(expectedString, contents); // Verify there's just 1 logged line Assert.AreEqual(1, contents.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Length); }
public void TestHelo() { WhiteListAddresses obAddresses = _antiSpam.WhiteListAddresses; 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. var 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", "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. CustomAsserts.Throws <DeliveryFailedException>(() => smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); Pop3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 1); }
public void TestSMTPAuthLocalToLocal() { SecurityRange range = SingletonProvider <TestSetup> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer"); range.RequireSMTPAuthLocalToLocal = true; range.Save(); Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var smtpClientSimulator = new SmtpClientSimulator(); string result = ""; CustomAsserts.Throws <DeliveryFailedException>(() => smtpClientSimulator.Send(account1.Address, account1.Address, "Mail 1", "Mail 1", out result)); Assert.IsTrue(result.Contains("SMTP authentication is required.")); range.RequireSMTPAuthLocalToLocal = false; range.Save(); smtpClientSimulator.Send(account1.Address, account1.Address, "Mail 1", "Mail 1", out result); CustomAsserts.AssertRecipientsInDeliveryQueue(0); }
public void TestMultipleLanguages() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string manyLanguages = "中文åäöん文t͡ɬɪŋ"; var message = new hMailServer.Message(); message.AddRecipient("test", account.Address); message.From = manyLanguages; message.FromAddress = account.Address; message.Subject = manyLanguages; message.Body = manyLanguages; message.Save(); CustomAsserts.AssertFolderMessageCount(account.IMAPFolders[0], 1); hMailServer.Message downloadedMessage = account.IMAPFolders[0].Messages[0]; Assert.AreEqual(manyLanguages, downloadedMessage.Subject); Assert.AreEqual(manyLanguages, downloadedMessage.From); Assert.AreEqual(manyLanguages + Environment.NewLine, downloadedMessage.Body); }
public void TestSMTPLogonFailure() { _settings.AutoBanOnLogonFailure = true; _settings.MaxInvalidLogonAttempts = 2; _settings.MaxInvalidLogonAttemptsWithin = 5; _settings.AutoBanMinutes = 3; Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var sim = new SmtpClientSimulator(); //[email protected] / test string errorMessage; sim.ConnectAndLogon("dGVzdEB0ZXN0LmNvbQ==", "dGVzdA==", out errorMessage); sim.Disconnect(); // confirm that we can retrieve welcome message. Assert.IsTrue(sim.GetWelcomeMessage().StartsWith("220")); // fail to log on 3 times. for (int i = 0; i < 2; i++) { CustomAsserts.Throws <System.Exception>(() => sim.ConnectAndLogon("dGVzdEB0ZXN0LmNvbQ==", "Vaffe==", out errorMessage)); sim.Disconnect(); if (i == 2) { Assert.IsTrue(errorMessage.Contains("Too many invalid logon attempts.")); } } Assert.IsTrue(sim.GetWelcomeMessage().Length == 0); string logText = LogHandler.ReadCurrentDefaultLog(); Assert.IsTrue(logText.Contains("Blocked either by IP range or by connection limit."), logText); }
public void TestAwstatsLog() { Settings settings = SingletonProvider <TestSetup> .Instance.GetApp().Settings; Logging logging = settings.Logging; logging.AWStatsEnabled = true; logging.Enabled = true; if (File.Exists(logging.CurrentAwstatsLog)) { File.Delete(logging.CurrentAwstatsLog); } Account oAccount1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); IPAddress localAddress = TestSetup.GetLocalIpAddress(); var smtpClientSimulator = new SmtpClientSimulator(false, 25, localAddress); // Delivery from external to local. smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1"); Pop3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 1); string contents = TestSetup.ReadExistingTextFile(logging.CurrentAwstatsLog); CustomAsserts.AssertDeleteFile(logging.CurrentAwstatsLog); string expectedString = string.Format("\[email protected]\[email protected]\t{0}\t127.0.0.1\tSMTP\t?\t250\t", localAddress); Assert.IsTrue(contents.Contains(expectedString), contents); // Failed delivery from local to local. CustomAsserts.Throws <DeliveryFailedException>(() => smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1")); contents = TestSetup.ReadExistingTextFile(logging.CurrentAwstatsLog); CustomAsserts.AssertDeleteFile(logging.CurrentAwstatsLog); expectedString = string.Format("\[email protected]\[email protected]\t{0}\t127.0.0.1\tSMTP\t?\t530\t", localAddress); Assert.IsTrue(contents.Contains(expectedString), contents); }
public void SquaresPagingTest(int pageNumber, int pageSize, int dataCount) { List <Square> squares = new List <Square>(); for (int i = 1; i <= dataCount; i++) { int j = i * 3 * (i % 3 == 1 ? -1 : 1) / (i % 2 == 1 * i ? 2 * i : 1); squares.Add(new Square($"{-j} {-j}.{j} {-j}.{-j} {j}.{j} {j}")); } _client.AddList("Test"); foreach (var square in squares) { _client.AddPoints(square.Points, "Test"); } var response = _client.GetSquares("Test", pageNumber, pageSize); var orderedSquares = response.Squares.OrderBy(c => c.Points, new Square.SquareComparer()); Assert.That(response.SquaresCount, Is.EqualTo(dataCount)); Assert.That(response.Squares.Count, Is.EqualTo(pageSize)); CollectionAssert.AreEqual(orderedSquares, response.Squares); CustomAsserts.SquarePointsAreSorted(response.Squares); }
public async Task ExtractNavigationPoints_TocNcxExample2WithoutPlayOrderAndElementIds_ReturnsNavigationPoints() { var docString = TestResources.TocNcxExample2; var doc = await XmlStructureFile.LoadFromTextAsync(string.Empty, docString); var preface1File = TestItemFactory.CreateFileFromString("preface01.html"); var testee = new NcxNavigationExtractor(); var result = testee.ExtractNavigationPoints(doc, new[] { preface1File }); var expected = new[] { new NavigationPoint("Preface", preface1File, null, 1, new [] { new NavigationPoint("Conventions", preface1File, "conventions", 2, new[] { new NavigationPoint("text", preface1File, "conventions_text", 3, new NavigationPoint[0]), }), }), }; CustomAsserts.AssertNavigationPointsAreEqual(result, expected); }
public void TestDomainMaxMessageSizeLimit() { _domain.MaxMessageSize = 0; _domain.Save(); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "secret1", 0); var message = new StringBuilder(); for (int i = 0; i < 10000; i++) { message.Append("ABCDEFGH"); } SmtpClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "TestSubject", message.ToString()); Pop3ClientSimulator.AssertMessageCount("*****@*****.**", "secret1", 1); _domain.MaxMessageSize = 50; _domain.Save(); CustomAsserts.Throws <DeliveryFailedException>(() => SmtpClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "TestSubject", message.ToString())); }
public void TestSMTPAuthExternalToExternal() { SecurityRange range = SingletonProvider <TestSetup> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer"); range.RequireSMTPAuthExternalToExternal = true; range.Save(); var smtpClientSimulator = new SmtpClientSimulator(); string result = ""; CustomAsserts.Throws <DeliveryFailedException>(() => smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result)); Assert.IsTrue(result.Contains("SMTP authentication is required.")); range.RequireSMTPAuthExternalToExternal = false; range.AllowDeliveryFromRemoteToRemote = false; range.Save(); CustomAsserts.Throws <DeliveryFailedException>(() => smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result)); Assert.IsTrue(result.Contains("550 Delivery is not allowed to this address.")); }
public void TestSMTPClient() { Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Assert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... var deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 550; int smtpServerPort = TestSetup.GetNextFreePort(); using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. AddRoutePointingAtLocalhostWithAuth(0, smtpServerPort); // Send message to this route. var smtp = new SmtpClientSimulator(); smtp.Send("*****@*****.**", "*****@*****.**", "Test", "Test message"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); string undeliveredMessages = _status.UndeliveredMessages; // Wait for the client to disconnect. server.WaitForCompletion(); CustomAsserts.AssertRecipientsInDeliveryQueue(0); EnsureNoPassword(); } }
public void TestAddTextToEmptyBody() { Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to the account. string messageText = @"Date: Thu, 03 Jul 2008 22:01:53 +0200\r\n" + "From: Test <*****@*****.**>\r\n" + "MIME-Version: 1.0\r\n" + "To: [email protected]\r\n" + "Subject: test\r\n" + "Content-Type: multipart/mixed;\r\n" + " boundary=\"------------050908050500020808050006\"\r\n" + "\r\n" + "This is a multi-part message in MIME format.\r\n" + "--------------050908050500020808050006\r\n" + "Content-Type: text/plain; charset=ISO-8859-1; format=flowed\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "\r\n" + "Test\r\n" + "\r\n" + "--------------050908050500020808050006\r\n" + "Content-Type: text/plain;\r\n" + " name=\"AUTOEXEC.BAT\"\r\n" + "Content-Transfer-Encoding: base64\r\n" + "Content-Disposition: inline;\r\n" + " filename=\"AUTOEXEC.BAT\"\r\n" + "\r\n" + "\r\n" + "--------------050908050500020808050006--\r\n"; SmtpClientSimulator.StaticSendRaw("*****@*****.**", "*****@*****.**", messageText); hMailServer.Message message = CustomAsserts.AssertRetrieveFirstMessage(account1.IMAPFolders.get_ItemByName("INBOX")); Assert.AreEqual(1, message.Attachments.Count); Assert.AreEqual("AUTOEXEC.BAT", message.Attachments[0].Filename); }
public void TestLargeMessageSuccess() { 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.StartListen(); // Add a route so we can connect to localhost. TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false); // Send message to this route. var messageBody = TestSetup.CreateLargeDummyMailBody(); var smtp = new SmtpClientSimulator(); var recipients = new List <string>(); recipients.Add("*****@*****.**"); smtp.Send("*****@*****.**", recipients, "Test", messageBody); // Wait for the client to disconnect. server.WaitForCompletion(); Assert.IsTrue(server.Conversation.Contains("\r\nDATA\r\n")); CustomAsserts.AssertRecipientsInDeliveryQueue(0, false); Assert.IsTrue(server.MessageData.Contains(messageBody)); } }
public void TestErrorOnMailFrom() { 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.MailFromResult = 561; server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can conenct to localhost. TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false); // 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 bounceMessage = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(bounceMessage.Contains("MAIL FROM:<*****@*****.**>")); Assert.IsTrue(bounceMessage.Contains("Remote server replied: 561")); } }
public void TestMaxSizeLimitation() { 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, "MySubject", 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")); }
public void TestFailureAfterDelivery() { _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.QuitResult = 421; server.StartListen(); // Add a route so we can connect to localhost. TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false); // Send message to this route. var smtp = new SmtpClientSimulator(); var recipients = new List <string>(); recipients.Add("*****@*****.**"); smtp.Send("*****@*****.**", recipients, "Test", "test of error after accepted delivery"); // Wait for the client to disconnect. server.WaitForCompletion(); CustomAsserts.AssertRecipientsInDeliveryQueue(0); Assert.IsTrue(server.MessageData.Contains("test of error after accepted delivery")); } }
public void TestSMTPClientTimeout() { 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.Sleep15MinutesAfterSessionStart; server.SecondsToWaitBeforeTerminate = 20 * 60; 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); }
public void TestInvalidBodyHash() { _antiSpam.DKIMVerificationEnabled = true; _antiSpam.DKIMVerificationFailureScore = 100; 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=PW2otvzd7V2TO8"+ "\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"); CustomAsserts.Throws <DeliveryFailedException>(() => SmtpClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText)); }
public static void AssertMessageCount(string accountName, string accountPassword, int expectedCount) { if (expectedCount == 0) { // just in case. CustomAsserts.AssertRecipientsInDeliveryQueue(0); } int timeout = 100; int actualCount = 0; while (timeout > 0) { var pop3ClientSimulator = new Pop3ClientSimulator(); actualCount = pop3ClientSimulator.GetMessageCount(accountName, accountPassword); if (actualCount == expectedCount) { return; } if (actualCount > expectedCount) { Assert.Fail( string.Format( "Actual count exceeds expected count. Account name: {2}, Actual: {0}, Expected: {1}.", actualCount, expectedCount, accountName)); } timeout--; Thread.Sleep(50); } Assert.Fail(string.Format("Wrong number of messages in inbox for {0}. Actual: {1}, Expected: {2}", accountName, actualCount, expectedCount)); }