public void TestAuthFailurePasswordInBounce() { Assert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.SimulatedError = SimulatedErrorType.ForceAuthenticationFailure; server.StartListen(); // Add a route so we can connect to localhost. hMailServer.Route route = AddRoutePointingAtLocalhost(5, 250, false); route.RelayerRequiresAuth = true; route.RelayerAuthUsername = "******"; route.SetRelayerAuthPassword("MySecretPassword"); // Send message to this route. SMTPClientSimulator smtp = new SMTPClientSimulator(); List<string> recipients = new List<string>(); recipients.Add("*****@*****.**"); Assert.IsTrue(smtp.Send("*****@*****.**", recipients, "Test", "Test message")); // Wait for the client to disconnect. server.WaitForCompletion(); Utilities.AssertRecipientsInDeliveryQueue(0); string messageText = POP3Simulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsFalse(messageText.Contains("MySecretPassword")); Assert.IsTrue(messageText.Contains("<Password removed>")); }
public void DoNotUseStartTlsIfNotEnabledButAvailable() { // No valid recipients... var deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); using (var server = new SMTPServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSSTARTTLSOptional)) { server.AddRecipientResult(deliveryResults); server.StartListen(); Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone); // Send message to this route. var smtp = new SMTPClientSimulator(); if (!smtp.Send("*****@*****.**", "*****@*****.**", "Test", "Test message")) { CustomAssert.Fail("Delivery failed"); } // Wait for the client to disconnect. server.WaitForCompletion(); TestSetup.AssertRecipientsInDeliveryQueue(0, false); Assert.IsNotNullOrEmpty(server.MessageData); CustomAssert.IsFalse(TestSetup.DefaultLogContains("220 Ready to start TLS")); } }
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 TestFailureAfterDelivery() { _application.Settings.SMTPNoOfTries = 3; _application.Settings.SMTPMinutesBetweenTry = 60; Assert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... Dictionary <string, int> deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.QuitResult = 421; 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 of error after accepted delivery")); // Wait for the client to disconnect. server.WaitForCompletion(); Utilities.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... Dictionary <string, int> deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.SimulatedError = SimulatedErrorType.Sleep15MinutesAfterSessionStart; server.SecondsToWaitBeforeTerminate = 20 * 60; server.StartListen(); // Add a route so we can connect to localhost. hMailServer.Route route = AddRoutePointingAtLocalhost(5, 250, false); route.RelayerRequiresAuth = true; route.RelayerAuthUsername = "******"; route.SetRelayerAuthPassword("MySecretPassword"); // Send message to this route. SMTPClientSimulator smtp = new SMTPClientSimulator(); List <string> recipients = new List <string>(); recipients.Add("*****@*****.**"); Assert.IsTrue(smtp.Send("*****@*****.**", recipients, "Test", "Test message")); // Wait for the client to disconnect. server.WaitForCompletion(); Utilities.AssertRecipientsInDeliveryQueue(0); }
public void TestDeliverySuccessDisconnectAfterMessageAccept() { Assert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... Dictionary <string, int> deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); server.SimulatedError = SimulatedErrorType.DisconnectAfterMessageAccept; // 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", "DisconnectAfterAcceptBeforeQuit")); // Wait for the client to disconnect. server.WaitForCompletion(); Utilities.AssertRecipientsInDeliveryQueue(0, false); Assert.IsTrue(server.MessageData.Contains("DisconnectAfterAcceptBeforeQuit")); }
public void TestSMTPClient() { hMailServer.Account account1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Assert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... Dictionary <string, int> deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 550; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. AddRoutePointingAtLocalhostWithAuth(0, 250); // Send message to this route. SMTPClientSimulator smtp = new SMTPClientSimulator(); Assert.IsTrue(smtp.Send("*****@*****.**", "*****@*****.**", "Test", "Test message")); Utilities.AssertRecipientsInDeliveryQueue(0); string undeliveredMessages = _status.UndeliveredMessages; // Wait for the client to disconnect. server.WaitForCompletion(); Utilities.AssertRecipientsInDeliveryQueue(0); EnsureNoPassword(); }
private string SendMessage(string body) { SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; int port = TestSetup.GetNextFreePort(); using (var server = new SMTPServerSimulator(1, port)) { server.SecondsToWaitBeforeTerminate = 60; server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. AddRoutePointingAtLocalhost(5, port); // Send message to this route. var smtp = new SMTPClientSimulator(); var recipients = new List <string>(); recipients.Add("*****@*****.**"); CustomAssert.IsTrue(smtp.Send("*****@*****.**", recipients, "Test", body)); // Wait for the client to disconnect. server.WaitForCompletion(); string messageData = server.MessageData; TestSetup.AssertRecipientsInDeliveryQueue(0); return(messageData); } }
public void TreatRecipientAsExternalDomainPermitted() { int smtpServerPort = TestSetup.GetNextFreePort(); Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false); route.TreatRecipientAsLocalDomain = false; route.Save(); SecurityRange range = SingletonProvider <TestSetup> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer"); range.AllowDeliveryFromRemoteToRemote = true; range.RequireSMTPAuthExternalToExternal = false; range.Save(); var deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; using (var server = new SMTPServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); var oSMTP = new SMTPClientSimulator(); string result; CustomAssert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result)); server.WaitForCompletion(); server.MessageData.Contains("Mail 1"); } }
private string SendMessage(string body) { hMailServer.Account account1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Dictionary <string, int> deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. AddRoutePointingAtLocalhost(5, 250); // Send message to this route. SMTPClientSimulator smtp = new SMTPClientSimulator(); List <string> recipients = new List <string>(); recipients.Add("*****@*****.**"); Assert.IsTrue(smtp.Send("*****@*****.**", recipients, "Test", body)); // Wait for the client to disconnect. server.WaitForCompletion(); string messageData = server.MessageData; Utilities.AssertRecipientsInDeliveryQueue(0); return(messageData); }
public void TestUseCase3DeliveryFromExternalUserToPrimaryViaBackup() { hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, 250, false); route.TreatRecipientAsLocalDomain = true; route.TreatSenderAsLocalDomain = false; route.Save(); Dictionary <string, int> deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); string result; Assert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result)); server.WaitForCompletion(); server.MessageData.Contains("Mail 1"); }
public void TestSMTPAuthExternalToRouteConfiguredAsLocal() { // First, make sure hMailServer requires auth. hMailServer.SecurityRange range = SingletonProvider <Utilities> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer"); range.RequireSMTPAuthExternalToExternal = true; range.RequireSMTPAuthLocalToExternal = true; range.Save(); hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, 250, false); route.TreatRecipientAsLocalDomain = true; route.TreatSenderAsLocalDomain = true; route.Save(); // Set up the simulating server to listen. Dictionary <string, int> deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); // Make sure we can't send to this route without using smtp auth. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); Assert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1")); server.WaitForCompletion(); Assert.IsTrue(server.MessageData.Contains("Mail 1"), server.MessageData); }
public void TestSendExternalToExternalPermitted() { SecurityRange range = SingletonProvider <TestSetup> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer"); range.RequireSMTPAuthExternalToExternal = false; range.Save(); // 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(); Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone); var oSMTP = new SMTPClientSimulator(); CustomAssert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Test message")); // This should now be processed via the rule -> route -> external server we've set up. server.WaitForCompletion(); CustomAssert.IsTrue(server.MessageData.Contains("Test message")); } }
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 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 TestMultipleHostsLimitMXHosts() { _settings.MaxNumberOfMXHosts = 1; // 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. Route route = SMTPClientTests.AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort); // Send message to this route. var smtp = new SMTPClientSimulator(); var recipients = new List <string>(); recipients.Add("*****@*****.**"); CustomAssert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Test", "Test")); // Wait for the client to disconnect. server.WaitForCompletion(); string log = TestSetup.ReadCurrentDefaultLog(); CustomAssert.IsTrue(log.Contains("Truncating MX server list.")); } }
public void TreatRecipientAsLocalDomain() { int smtpServerPort = TestSetup.GetNextFreePort(); Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false); route.TreatRecipientAsLocalDomain = true; route.Save(); var deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; using (var server = new SMTPServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); var oSMTP = new SMTPClientSimulator(); string result; CustomAssert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result)); server.WaitForCompletion(); server.MessageData.Contains("Mail 1"); } }
public void ShouldBePossibleToSendToRouteWithTargetIPAddress() { // 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(); Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSNone); route.TargetSMTPHost = "127.0.0.1"; route.Save(); var smtpSimulator = new SMTPClientSimulator(); CustomAssert.IsTrue(smtpSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Test message")); // This should now be processed via the rule -> route -> external server we've set up. server.WaitForCompletion(); var log = TestSetup.ReadCurrentDefaultLog(); CustomAssert.IsTrue(server.MessageData.Contains("Test message")); } }
public void TestDeliverToServerNotSupportingEHLO() { CustomAssert.AreEqual(0, _status.UndeliveredMessages.Length); var deliveryResults = new Dictionary <string, int>() { { "*****@*****.**", 250 } }; int smtpServerPort = TestSetup.GetNextFreePort(); using (var server = new SMTPServerSimulator(1, smtpServerPort)) { server.ServerSupportsEhlo = false; server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can conenct to localhost. SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone); // Send message to this route. if (!SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Test", "Test message")) { CustomAssert.Fail("Delivery failed"); } // Wait for the client to disconnect. server.WaitForCompletion(); TestSetup.AssertRecipientsInDeliveryQueue(0, false); CustomAssert.IsTrue(server.MessageData.Contains("Test message")); } }
public void SmtpServerNOTSupportingStartTls_StartTlsRequired() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // 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, eConnectionSecurity.eCSNone)) { server.SetCertificate(SslSetup.GetCertificate()); server.AddRecipientResult(deliveryResults); server.StartListen(); Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSSTARTTLSRequired); var smtpClient = new SMTPClientSimulator(); CustomAssert.IsTrue(smtpClient.Send(account.Address, "*****@*****.**", "Test", "Test message")); TestSetup.AssertRecipientsInDeliveryQueue(0); // This should now be processed via the rule -> route -> external server we've set up. server.WaitForCompletion(); var msg = POP3ClientSimulator.AssertGetFirstMessageText("*****@*****.**", "test"); CustomAssert.IsTrue(msg.Contains("Server does not support STARTTLS")); } }
public void SmtpServerSupportingStartTls_StartTlsOptional() { Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // 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, eConnectionSecurity.eCSSTARTTLSRequired)) { server.SetCertificate(SslSetup.GetCertificate()); server.AddRecipientResult(deliveryResults); server.StartListen(); Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSSTARTTLSOptional); var smtpClient = new SMTPClientSimulator(); CustomAssert.IsTrue(smtpClient.Send(account.Address, "*****@*****.**", "Test", "Test message")); TestSetup.AssertRecipientsInDeliveryQueue(0); server.WaitForCompletion(); CustomAssert.IsTrue(server.MessageData.Contains("Test message")); } }
public void TestDeliverySuccessSingleRecipientMissingQuitResponse() { CustomAssert.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(); server.SimulatedError = SimulatedErrorType.DisconnectWithoutReplyOnQuit; // Add a route so we can connect to localhost. AddRoutePointingAtLocalhost(5, smtpServerPort, false); // Send message to this route. var smtp = new SMTPClientSimulator(); var recipients = new List <string>(); recipients.Add("*****@*****.**"); CustomAssert.IsTrue(smtp.Send("*****@*****.**", recipients, "Test", "DeliverySuccessNoQuitResponse")); // Wait for the client to disconnect. server.WaitForCompletion(); TestSetup.AssertRecipientsInDeliveryQueue(0, false); CustomAssert.IsTrue(server.MessageData.Contains("DeliverySuccessNoQuitResponse")); } }
public void TestDeliverToMyselfOnLocalPortAfterChangedLocalPort() { TCPIPPorts oPorts = _application.Settings.TCPIPPorts; for (int i = 0; i < oPorts.Count; i++) { TCPIPPort oTestPort = oPorts[i]; if (oTestPort.Protocol == eSessionType.eSTIMAP) { oTestPort.PortNumber = 14300; } else if (oTestPort.Protocol == eSessionType.eSTSMTP) { oTestPort.PortNumber = 11000; } else if (oTestPort.Protocol == eSessionType.eSTPOP3) { oTestPort.PortNumber = 2500; } oTestPort.Save(); } _application.Stop(); _application.Start(); // Set up a server and start listening. 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. AddRoutePointingAtLocalhost(5, smtpServerPort, false); // Send message to this route. var sim = new SMTPClientSimulator(false, 11000); sim.Send("*****@*****.**", "*****@*****.**", "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); TestSetup.AssertRecipientsInDeliveryQueue(0, false); CustomAssert.IsTrue(server.MessageData.Contains("Test message")); } oPorts.SetDefault(); _application.Stop(); _application.Start(); }
public void TestFatalDeliveryFailure() { _application.Settings.Logging.Enabled = true; _application.Settings.Logging.LogSMTP = true; _application.Settings.Logging.LogTCPIP = true; _application.Settings.Logging.LogDebug = true; CustomAssert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... var deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 550; int smtpServerPort = TestSetup.GetNextFreePort(); using (var server = new SMTPServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can conenct to localhost. AddRoutePointingAtLocalhost(0, smtpServerPort, false); // Send message to this route. var smtp = new SMTPClientSimulator(); var recipients = new List <string>(); recipients.Add("*****@*****.**"); CustomAssert.IsTrue(smtp.Send("*****@*****.**", recipients, "Test", "Test message")); string undeliveredMessages = _status.UndeliveredMessages; // Wait for the client to disconnect. server.WaitForCompletion(); // wait for the message to be delivered. for (int i = 1; i <= 40; i++) { CustomAssert.IsFalse(i == 40); if (_status.UndeliveredMessages.Contains("\[email protected]") || _status.UndeliveredMessages.Length == 0) { break; } Thread.Sleep(250); } TestSetup.AssertRecipientsInDeliveryQueue(0, true); string bounceMessage = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); CustomAssert.IsTrue(bounceMessage.Contains("Remote server (127.0.0.1) issued an error.")); CustomAssert.IsTrue(bounceMessage.Contains("550 [email protected]")); } }
public void TestMultipleHostsHalfDeliveryOnFirstPermanentOnSecond() { CustomAssert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... var deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; deliveryResults["*****@*****.**"] = 250; deliveryResults["*****@*****.**"] = 450; var deliveryResultsSecond = new Dictionary <string, int>(); deliveryResultsSecond["*****@*****.**"] = 550; deliveryResultsSecond["*****@*****.**"] = 550; deliveryResultsSecond["*****@*****.**"] = 500; int smtpServerPort = TestSetup.GetNextFreePort(); using (var server = new SMTPServerSimulator(2, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.AddRecipientResult(deliveryResultsSecond); server.StartListen(); // Add a route so we can connect to localhost. AddRoutePointingAtLocalhostMultipleHosts(1, smtpServerPort); // Send message to this route. var smtp = new SMTPClientSimulator(); var recipients = new List <string>(); recipients.Add("*****@*****.**"); recipients.Add("*****@*****.**"); recipients.Add("*****@*****.**"); CustomAssert.IsTrue(smtp.Send("*****@*****.**", recipients, "Test", "Accepted message")); // Wait for the client to disconnect. server.WaitForCompletion(); // Trigger a sending of the bounce message. TestSetup.AssertRecipientsInDeliveryQueue(0, true); string bounceMessage = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); CustomAssert.IsFalse(bounceMessage.Contains("RCPT TO:<*****@*****.**>")); CustomAssert.IsFalse(bounceMessage.Contains("RCPT TO:<*****@*****.**>")); CustomAssert.IsTrue(bounceMessage.Contains("RCPT TO:<*****@*****.**>")); CustomAssert.IsTrue(bounceMessage.Contains("500 [email protected]")); } }
public void TestMultipleHostsTemporaryFailureDeliveryOnSecondServer() { CustomAssert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... var deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; deliveryResults["*****@*****.**"] = 250; deliveryResults["*****@*****.**"] = 450; var deliveryResultsSecond = new Dictionary <string, int>(); deliveryResultsSecond["*****@*****.**"] = 250; deliveryResultsSecond["*****@*****.**"] = 250; deliveryResultsSecond["*****@*****.**"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); using (var server = new SMTPServerSimulator(2, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.AddRecipientResult(deliveryResultsSecond); server.StartListen(); // Add a route so we can connect to localhost. AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort); // Send message to this route. var smtp = new SMTPClientSimulator(); var recipients = new List <string>(); recipients.Add("*****@*****.**"); recipients.Add("*****@*****.**"); recipients.Add("*****@*****.**"); if (!smtp.Send("*****@*****.**", recipients, "Test", "Accepted message")) { CustomAssert.Fail("Delivery failed"); } // Wait for the client to disconnect. server.WaitForCompletion(); // Trigger a sending of the bounce message. TestSetup.AssertRecipientsInDeliveryQueue(0); CustomAssert.IsTrue(server.MessageData.Contains("Accepted message")); } }
public void TestTemporaryFailure() { CustomAssert.AreEqual(0, _status.UndeliveredMessages.Length); var deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 452; int smtpServerPort = TestSetup.GetNextFreePort(); using (var server = new SMTPServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. AddRoutePointingAtLocalhost(2, smtpServerPort, false); // Send message to this route. var smtp = new SMTPClientSimulator(); var recipients = new List <string>(); recipients.Add("*****@*****.**"); CustomAssert.IsTrue(smtp.Send("*****@*****.**", recipients, "Test", "Test message")); // Wait for the client to disconnect. server.WaitForCompletion(); CustomAssert.AreNotEqual(0, _status.UndeliveredMessages.Length); } using (var server = new SMTPServerSimulator(1, smtpServerPort))// Start to listen again. { server.AddRecipientResult(deliveryResults); server.StartListen(); // Deliver the message to the server and then deliver the bounce message. TestSetup.AssertRecipientsInDeliveryQueue(0, true); // Wait for the client to disconnect. server.WaitForCompletion(); CustomAssert.IsFalse(server.Conversation.Contains("\r\nDATA\r\n")); } // Now the message has bounced. string message = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); CustomAssert.IsTrue(message.Contains("452 [email protected]")); CustomAssert.IsTrue(message.Contains("Tried 2 time(s)")); }
public void RoutesShouldConsolidateRecipients() { // 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)) { server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route pointing at localhost Route route = _settings.Routes.Add(); route.DomainName = "test.com"; route.TargetSMTPHost = "localhost"; route.TargetSMTPPort = smtpServerPort; route.NumberOfTries = 1; route.MinutesBetweenTry = 5; route.TreatRecipientAsLocalDomain = true; route.TreatSenderAsLocalDomain = true; route.AllAddresses = true; route.Save(); var smtpClient = new SMTPClientSimulator(); var recipients = new List <string>() { "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**" }; CustomAssert.IsTrue(smtpClient.Send("*****@*****.**", recipients, "Test", "Test message")); TestSetup.AssertRecipientsInDeliveryQueue(0); server.WaitForCompletion(); CustomAssert.IsTrue(server.MessageData.Contains("Test message")); CustomAssert.AreEqual(deliveryResults.Count, server.RcptTosReceived); } }
public void DomainAliasesShouldNotRewriteRecipientList() { DomainAlias oDA = _domain.DomainAliases.Add(); oDA.AliasName = "dummy-example.com"; oDA.Save(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // 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(); Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSNone); // Now send a message from [email protected] to [email protected]. // Error scenario: // In the recipientlist, otherdomain.com gets rewritten to test.com // since there's a domain alias named otherdomain.co on the domain // test.com. // // This should not happen. Otherdomain.com is an alias for test.com, // but we shouldn't actually modify the recipient address just because // of this. var smtpClient = new SMTPClientSimulator(); CustomAssert.IsTrue(smtpClient.Send(account.Address, "*****@*****.**", "Test", "Test message")); TestSetup.AssertRecipientsInDeliveryQueue(0); POP3ClientSimulator.AssertMessageCount(account.Address, "test", 0); // This should now be processed via the rule -> route -> external server we've set up. server.WaitForCompletion(); CustomAssert.IsTrue(server.MessageData.Contains("Test message")); } }
public void RoutesShouldHaveHigherPrioThanSMTPRelay() { // Set up a server listening on port 250 which accepts email for [email protected] var deliveryResults = new Dictionary <string, int>(); deliveryResults["*****@*****.**"] = 250; // We set the SMTP relayer here, but this should be ignored since the recipient's // address matches a route set up (test.com). _application.Settings.SMTPRelayer = "example.com"; 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 = "test.com"; route.TargetSMTPHost = "localhost"; route.TargetSMTPPort = smtpServerPort; route.NumberOfTries = 1; route.MinutesBetweenTry = 5; route.TreatRecipientAsLocalDomain = true; route.TreatSenderAsLocalDomain = true; route.AllAddresses = false; route.Save(); // Make sure only the specific user is valid. RouteAddress routeAddress = route.Addresses.Add(); routeAddress.Address = "user@" + _domain.Name; routeAddress.Save(); SingletonProvider <TestSetup> .Instance.AddAlias(_domain, "*****@*****.**", "*****@*****.**"); var smtpClient = new SMTPClientSimulator(); CustomAssert.IsTrue(smtpClient.Send("*****@*****.**", "*****@*****.**", "Test", "Test message")); TestSetup.AssertRecipientsInDeliveryQueue(0); server.WaitForCompletion(); CustomAssert.IsTrue(server.MessageData.Contains("Test message")); } }
public void TestDeliverySuccess50Recipients() { CustomAssert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... var deliveryResults = new Dictionary <string, int>(); for (int i = 0; i < 50; i++) { deliveryResults["user" + i.ToString() + "@dummy-example.com"] = 250; } int smtpServerPort = TestSetup.GetNextFreePort(); using (var server = new SMTPServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can conenct to localhost. AddRoutePointingAtLocalhost(5, smtpServerPort, false); // Send message to this route. var smtp = new SMTPClientSimulator(); var recipients = new List <string>(); for (int i = 0; i < 50; i++) { recipients.Add("user" + i.ToString() + "@dummy-example.com"); } if (!smtp.Send("*****@*****.**", recipients, "Test", "Test message")) { CustomAssert.Fail("Delivery failed"); } // Wait for the client to disconnect. server.WaitForCompletion(); TestSetup.AssertRecipientsInDeliveryQueue(0, false); CustomAssert.IsTrue(server.MessageData.Contains("Test message")); } }
public void TestMultipleHostsHalfDeliveryOnFirstPermanentOnSecond() { Assert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 250; deliveryResults["*****@*****.**"] = 250; deliveryResults["*****@*****.**"] = 450; Dictionary<string, int> deliveryResultsSecond = new Dictionary<string, int>(); deliveryResultsSecond["*****@*****.**"] = 550; deliveryResultsSecond["*****@*****.**"] = 550; deliveryResultsSecond["*****@*****.**"] = 500; SMTPServerSimulator server = new SMTPServerSimulator(2, 250); server.AddRecipientResult(deliveryResults); server.AddRecipientResult(deliveryResultsSecond); server.StartListen(); // Add a route so we can connect to localhost. AddRoutePointingAtLocalhostMultipleHosts(1); // Send message to this route. SMTPClientSimulator smtp = new SMTPClientSimulator(); List<string> recipients = new List<string>(); recipients.Add("*****@*****.**"); recipients.Add("*****@*****.**"); recipients.Add("*****@*****.**"); Assert.IsTrue(smtp.Send("*****@*****.**", recipients, "Test", "Accepted message")); // Wait for the client to disconnect. server.WaitForCompletion(); // Trigger a sending of the bounce message. Utilities.AssertRecipientsInDeliveryQueue(0, true); string bounceMessage = POP3Simulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsFalse(bounceMessage.Contains("RCPT TO:<*****@*****.**>")); Assert.IsFalse(bounceMessage.Contains("RCPT TO:<*****@*****.**>")); Assert.IsTrue(bounceMessage.Contains("RCPT TO:<*****@*****.**>")); Assert.IsTrue(bounceMessage.Contains("500 [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 TestDeliveryAttempts() { // Add an account hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account adminAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); // Set up a rule to forward from account1 to 2 and 3. hMailServer.Rule oRule = _application.Rules.Add(); oRule.Name = "Criteria test"; oRule.Active = true; oRule.UseAND = true; hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add(); oRuleCriteria.UsePredefined = true; oRuleCriteria.PredefinedField = hMailServer.eRulePredefinedField.eFTDeliveryAttempts; oRuleCriteria.MatchType = hMailServer.eRuleMatchType.eMTEquals; oRuleCriteria.MatchValue = "2"; oRuleCriteria.Save(); // The second time we try to deliver an email, forward a copy to the admin! hMailServer.RuleAction oRuleAction = oRule.Actions.Add(); oRuleAction.Type = hMailServer.eRuleActionType.eRAForwardEmail; oRuleAction.To = adminAccount.Address; oRuleAction.Save(); // And then delete it. oRuleAction = oRule.Actions.Add(); oRuleAction.Type = hMailServer.eRuleActionType.eRADeleteEmail; oRuleAction.Save(); // Save the rule in the database oRule.Save(); Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 452; SMTPServerSimulator smtpServer = new SMTPServerSimulator(1, 250); smtpServer.AddRecipientResult(deliveryResults); smtpServer.StartListen(); // Add a route so we can connect to localhost. SMTPClientTests.AddRoutePointingAtLocalhost(2, 250, false); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); // Test to send the message to account 1. Make sure a copy is created by this rule. oSMTP.Send(account.Address, new List<string>() { "*****@*****.**" }, "Test", "Test message."); smtpServer.WaitForCompletion(); Utilities.AssertRecipientsInDeliveryQueue(0, true); string first = POP3Simulator.AssertGetFirstMessageText(adminAccount.Address, "test"); Assert.IsTrue(first.Contains("X-hMailServer-LoopCount: 1"), first); POP3Simulator.AssertMessageCount(account.Address, "test", 0); }
public void TestDeliverToExternalMimeRecipientsEnabled() { List<string> messages = new List<string>(); string message = "From: [email protected]\r\n" + "To: \"Test\" <*****@*****.**>, \"ExternalGuy\" <*****@*****.**>\r\n" + "Subject: Test\r\n" + "\r\n" + "Hello!"; messages.Add(message); int port = 1110; POP3Server pop3Server = new POP3Server(1, port, messages); pop3Server.StartListen(); Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator smtpServer = new SMTPServerSimulator(1, 250); smtpServer.AddRecipientResult(deliveryResults); smtpServer.StartListen(); // Add a route so we can connect to localhost. hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, 250, false); route.TreatSecurityAsLocalDomain = true; route.Save(); hMailServer.Account account1 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account account2 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account catchallAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); _domain.Postmaster = catchallAccount.Address; _domain.Save(); hMailServer.FetchAccount fa = account1.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 = true; fa.EnableRouteRecipients = true; fa.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); fa.Delete(); string downloadedMessage1 = POP3Simulator.AssertGetFirstMessageText(account2.Address, "test"); POP3Simulator.AssertMessageCount(account1.Address, "test", 0); POP3Simulator.AssertMessageCount(catchallAccount.Address, "test", 0); Assert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1); // Make sure the exernal recipient has received his copy. smtpServer.WaitForCompletion(); string messageData = smtpServer.MessageData; Assert.IsTrue(messageData.Contains(messageData), messageData); Utilities.AssertRecipientsInDeliveryQueue(0, false); }
public void TestDeliverySuccess50Recipients() { Assert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); for (int i = 0; i < 50; i++) deliveryResults["user" + i.ToString() + "@dummy-example.com"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); 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>(); for (int i = 0; i < 50; i++) recipients.Add("user" + i.ToString() + "@dummy-example.com"); if (!smtp.Send("*****@*****.**", recipients, "Test", "Test message")) Assert.Fail("Delivery failed"); // Wait for the client to disconnect. server.WaitForCompletion(); Utilities.AssertRecipientsInDeliveryQueue(0, false); Assert.IsTrue(server.MessageData.Contains("Test message")); }
public void TestSMTPClient() { hMailServer.Account account1 = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); Assert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 550; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. AddRoutePointingAtLocalhostWithAuth(0, 250); // Send message to this route. SMTPClientSimulator smtp = new SMTPClientSimulator(); Assert.IsTrue(smtp.Send("*****@*****.**", "*****@*****.**", "Test", "Test message")); Utilities.AssertRecipientsInDeliveryQueue(0); string undeliveredMessages = _status.UndeliveredMessages; // Wait for the client to disconnect. server.WaitForCompletion(); Utilities.AssertRecipientsInDeliveryQueue(0); EnsureNoPassword(); }
public void TestFailureAfterDelivery() { _application.Settings.SMTPNoOfTries = 3; _application.Settings.SMTPMinutesBetweenTry = 60; Assert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.QuitResult = 421; 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 of error after accepted delivery")); // Wait for the client to disconnect. server.WaitForCompletion(); Utilities.AssertRecipientsInDeliveryQueue(0); Assert.IsTrue(server.MessageData.Contains("test of error after accepted delivery")); }
public void TestTemporaryFailure() { Assert.AreEqual(0, _status.UndeliveredMessages.Length); Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 452; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. AddRoutePointingAtLocalhost(2, 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.AreNotEqual(0, _status.UndeliveredMessages.Length); // Start to listen again. server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); // Deliver the message to the server and then deliver the bounce message. Utilities.AssertRecipientsInDeliveryQueue(0, true); // Wait for the client to disconnect. server.WaitForCompletion(); Assert.IsFalse(server.Conversation.Contains("\r\nDATA\r\n")); // Now the message has bounced. string message = POP3Simulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(message.Contains("452 [email protected]")); Assert.IsTrue(message.Contains("Tried 2 time(s)")); }
public void SendMessageToAliasForwardToRoute() { // Set up a server listening on port 250 which accepts email for [email protected] Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route pointing at localhost hMailServer.Route route = _settings.Routes.Add(); route.DomainName = "test.com"; route.TargetSMTPHost = "localhost"; route.TargetSMTPPort = 250; route.NumberOfTries = 1; route.MinutesBetweenTry = 5; route.TreatRecipientAsLocalDomain = true; route.TreatSenderAsLocalDomain = true; route.AllAddresses = false; route.Save(); // Make sure only the specific user is valid. hMailServer.RouteAddress routeAddress = route.Addresses.Add(); routeAddress.Address = "user@" + _domain.Name; routeAddress.Save(); SingletonProvider<Utilities>.Instance.AddAlias(_domain, "*****@*****.**", "*****@*****.**"); SMTPClientSimulator smtpClient = new SMTPClientSimulator(); Assert.IsTrue(smtpClient.Send("*****@*****.**", "*****@*****.**", "Test", "Test message")); Utilities.AssertRecipientsInDeliveryQueue(0); server.WaitForCompletion(); Assert.IsTrue(server.MessageData.Contains("Test message")); }
public void TestMultipleHostsLimitMXHosts() { _settings.MaxNumberOfMXHosts = 1; // No valid recipients... Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhostMultipleHosts(2); // Send message to this route. SMTPClientSimulator smtp = new SMTPClientSimulator(); List<string> recipients = new List<string>(); recipients.Add("*****@*****.**"); Assert.IsTrue(SMTPClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Test", "Test")); // Wait for the client to disconnect. server.WaitForCompletion(); string log = Utilities.ReadCurrentDefaultLog(); Assert.IsTrue(log.Contains("Truncating MX server list.")); }
public void DomainAliasesShouldNotRewriteRecipientList() { hMailServer.Application application = SingletonProvider<Utilities>.Instance.GetApp(); ; hMailServer.DomainAlias oDA = _domain.DomainAliases.Add(); oDA.AliasName = "dummy-example.com"; oDA.Save(); hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); // Set up a server listening on port 250 which accepts email for [email protected] Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, 250, true); // Now send a message from [email protected] to [email protected]. // Error scenario: // In the recipientlist, otherdomain.com gets rewritten to test.com // since there's a domain alias named otherdomain.co on the domain // test.com. // // This should not happen. Otherdomain.com is an alias for test.com, // but we shouldn't actually modify the recipient address just because // of this? SMTPClientSimulator smtpClient = new SMTPClientSimulator(); Assert.IsTrue(smtpClient.Send(account.Address, "*****@*****.**", "Test", "Test message")); Utilities.AssertRecipientsInDeliveryQueue(0); POP3Simulator.AssertMessageCount(account.Address, "test", 0); // This should now be processed via the rule -> route -> external server we've set up. server.WaitForCompletion(); Assert.IsTrue(server.MessageData.Contains("Test message")); }
public void TestSMTPAuthExternalToRouteConfiguredAsLocal() { // First, make sure hMailServer requires auth. hMailServer.SecurityRange range = SingletonProvider<Utilities>.Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer"); range.RequireSMTPAuthExternalToExternal = true; range.RequireSMTPAuthLocalToExternal = true; range.Save(); hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, 250, false); route.TreatRecipientAsLocalDomain = true; route.TreatSenderAsLocalDomain = true; route.Save(); // Set up the simulating server to listen. Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); // Make sure we can't send to this route without using smtp auth. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); Assert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1")); server.WaitForCompletion(); Assert.IsTrue(server.MessageData.Contains("Mail 1"), server.MessageData); }
public void ActionSendUsingRoute() { // add an account to send from hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); // Add a route so we can conenct to localhost. hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(5, 250, false); // Add a global send-using-route rule hMailServer.Rule oRule = _application.Rules.Add(); oRule.Name = "Send using route"; oRule.Active = true; hMailServer.RuleCriteria oRuleCriteria = oRule.Criterias.Add(); oRuleCriteria.UsePredefined = false; oRuleCriteria.HeaderField = "Subject"; oRuleCriteria.MatchType = hMailServer.eRuleMatchType.eMTContains; oRuleCriteria.MatchValue = "TestString"; oRuleCriteria.Save(); // Add action hMailServer.RuleAction oRuleAction = oRule.Actions.Add(); oRuleAction.Type = hMailServer.eRuleActionType.eRASendUsingRoute; oRuleAction.RouteID = route.ID; oRuleAction.Save(); oRule.Save(); // Send message and confirm that the route does not affect it. SMTPClientSimulator smtp = new SMTPClientSimulator(); List<string> recipients = new List<string>(); recipients.Add("*****@*****.**"); if (!smtp.Send("*****@*****.**", recipients, "Test", "Test message")) Assert.Fail("Delivery failed"); string message = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(message.Contains("Test message")); // Send a message and confirm that the rule affects it. Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 550; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); // Send the actual message recipients = new List<string>(); recipients.Add("*****@*****.**"); if (!smtp.Send("*****@*****.**", recipients, "TestString", "Test message")) Assert.Fail("Delivery failed"); server.WaitForCompletion(); // Submit the bounce message... Utilities.AssertRecipientsInDeliveryQueue(0); // Download it. message = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(message.Contains("550")); Assert.IsTrue(message.Contains("*****@*****.**")); }
public void TestFatalDeliveryFailure() { _application.Settings.Logging.Enabled = true; _application.Settings.Logging.LogSMTP = true; _application.Settings.Logging.LogTCPIP = true; _application.Settings.Logging.LogDebug = true; Assert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 550; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can conenct to localhost. AddRoutePointingAtLocalhost(0, 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")); string undeliveredMessages = _status.UndeliveredMessages; // Wait for the client to disconnect. server.WaitForCompletion(); // wait for the message to be delivered. for (int i = 1; i <= 40; i++) { Assert.IsFalse(i == 40); if (_status.UndeliveredMessages.Contains("\[email protected]") || _status.UndeliveredMessages.Length == 0) break; Thread.Sleep(250); } Utilities.AssertRecipientsInDeliveryQueue(0, true); string bounceMessage = POP3Simulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(bounceMessage.Contains("Remote server (127.0.0.1) issued an error.")); Assert.IsTrue(bounceMessage.Contains("550 [email protected]")); }
public void TestFailureAfterReceivedHelloBanner() { _application.Settings.SMTPNoOfTries = 3; _application.Settings.SMTPMinutesBetweenTry = 60; Assert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.SimulatedError = SimulatedErrorType.DisconnectAfterSessionStart; server.StartListen(); // Add a route so we can connect to localhost. AddRoutePointingAtLocalhost(1, 250, false); // Send message to this route. SMTPClientSimulator smtp = new SMTPClientSimulator(); List<string> recipients = new List<string>(); recipients.Add("*****@*****.**"); Assert.IsTrue(smtp.Send(_account.Address, recipients, "Test", "Test message")); // Wait for the client to disconnect. server.WaitForCompletion(); // Force the message to be bounced. Utilities.AssertRecipientsInDeliveryQueue(0, true); string bounce = POP3Simulator.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 TestSMTPClientTimeout() { Assert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.SimulatedError = SimulatedErrorType.Sleep15MinutesAfterSessionStart; server.SecondsToWaitBeforeTerminate = 20 * 60; server.StartListen(); // Add a route so we can connect to localhost. hMailServer.Route route = AddRoutePointingAtLocalhost(5, 250, false); route.RelayerRequiresAuth = true; route.RelayerAuthUsername = "******"; route.SetRelayerAuthPassword("MySecretPassword"); // Send message to this route. SMTPClientSimulator smtp = new SMTPClientSimulator(); List<string> recipients = new List<string>(); recipients.Add("*****@*****.**"); Assert.IsTrue(smtp.Send("*****@*****.**", recipients, "Test", "Test message")); // Wait for the client to disconnect. server.WaitForCompletion(); Utilities.AssertRecipientsInDeliveryQueue(0); }
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 TestDeliverySuccessSingleRecipientMissingQuitResponse() { Assert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); server.SimulatedError = SimulatedErrorType.DisconnectWithoutReplyOnQuit; // 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", "DeliverySuccessNoQuitResponse")); // Wait for the client to disconnect. server.WaitForCompletion(); Utilities.AssertRecipientsInDeliveryQueue(0, false); Assert.IsTrue(server.MessageData.Contains("DeliverySuccessNoQuitResponse")); }
public void TestPartialTemporaryErrorFailure() { Assert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 250; deliveryResults["*****@*****.**"] = 250; deliveryResults["*****@*****.**"] = 400; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. AddRoutePointingAtLocalhost(2, 250, false); // 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(); // Trigger a sending of the bounce message. Utilities.AssertRecipientsInDeliveryQueue(1); Assert.AreEqual(-1, _status.UndeliveredMessages.IndexOf("*****@*****.**")); Assert.AreEqual(-1, _status.UndeliveredMessages.IndexOf("*****@*****.**")); Assert.AreNotEqual(-1, _status.UndeliveredMessages.IndexOf("*****@*****.**")); Assert.IsTrue(server.MessageData.Contains("Test message")); // Attempt to deliver the message again. server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); Utilities.SendMessagesInQueue(); server.WaitForCompletion(); // Utilities.AssertRecipientsInDeliveryQueue(0); string bounceMessage = POP3Simulator.AssertGetFirstMessageText("*****@*****.**", "test"); Assert.IsTrue(bounceMessage.Contains("400 [email protected]")); Assert.IsTrue(bounceMessage.Contains("Tried 2 time(s)")); Assert.IsFalse(bounceMessage.Contains("*****@*****.**")); Assert.IsFalse(bounceMessage.Contains("*****@*****.**")); }
public void TestDeliverToMyselfOnLocalPortAfterChangedLocalPort() { hMailServer.TCPIPPorts oPorts = _application.Settings.TCPIPPorts; for (int i = 0; i < oPorts.Count; i++) { hMailServer.TCPIPPort oTestPort = oPorts[i]; if (oTestPort.Protocol == hMailServer.eSessionType.eSTIMAP) oTestPort.PortNumber = 14300; else if (oTestPort.Protocol == hMailServer.eSessionType.eSTSMTP) oTestPort.PortNumber = 11000; else if (oTestPort.Protocol == hMailServer.eSessionType.eSTPOP3) oTestPort.PortNumber = 2500; oTestPort.Save(); } _application.Stop(); _application.Start(); // Set up a server and start listening. Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 25); server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. AddRoutePointingAtLocalhost(5, 25, false); // Send message to this route. SMTPClientSimulator sim = new SMTPClientSimulator(false, 11000); sim.Send("*****@*****.**", "*****@*****.**", "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); Utilities.AssertRecipientsInDeliveryQueue(0, false); Assert.IsTrue(server.MessageData.Contains("Test message")); oPorts.SetDefault(); _application.Stop(); _application.Start(); }
public void TestMultipleHostsTemporaryFailureDeliveryOnSecondServer() { Assert.AreEqual(0, _status.UndeliveredMessages.Length); // No valid recipients... Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 250; deliveryResults["*****@*****.**"] = 250; deliveryResults["*****@*****.**"] = 450; Dictionary<string, int> deliveryResultsSecond = new Dictionary<string, int>(); deliveryResultsSecond["*****@*****.**"] = 250; deliveryResultsSecond["*****@*****.**"] = 250; deliveryResultsSecond["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(2, 250); server.AddRecipientResult(deliveryResults); server.AddRecipientResult(deliveryResultsSecond); server.StartListen(); // Add a route so we can connect to localhost. 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", "Accepted message")) Assert.Fail("Delivery failed"); // Wait for the client to disconnect. server.WaitForCompletion(); // Trigger a sending of the bounce message. Utilities.AssertRecipientsInDeliveryQueue(0); Assert.IsTrue(server.MessageData.Contains("Accepted message")); }
public void TreatRecipientAsExternalDomainPermitted() { hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, 250, false); route.TreatRecipientAsLocalDomain = false; route.Save(); hMailServer.SecurityRange range = SingletonProvider<Utilities>.Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer"); range.AllowDeliveryFromRemoteToRemote = true; range.RequireSMTPAuthExternalToExternal = false; range.Save(); Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); string result; Assert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result)); server.WaitForCompletion(); server.MessageData.Contains("Mail 1"); }
public void TreatRecipientAsLocalDomain() { hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, 250, false); route.TreatRecipientAsLocalDomain = true; route.Save(); Dictionary<string, int> deliveryResults = new Dictionary<string, int>(); deliveryResults["*****@*****.**"] = 250; SMTPServerSimulator server = new SMTPServerSimulator(1, 250); server.AddRecipientResult(deliveryResults); server.StartListen(); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); string result; Assert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result)); server.WaitForCompletion(); server.MessageData.Contains("Mail 1"); }