private void SetupRoutes() { hMailServer.Routes routes = _application.Settings.Routes; hMailServer.Route route = routes.Add(); route.DomainName = "test1.com"; route.Description = "description"; route.UseSSL = true; route.TreatSenderAsLocalDomain = true; route.TreatRecipientAsLocalDomain = false; route.Save(); route = routes.Add(); route.DomainName = "test2.com"; route.Description = "description2"; route.UseSSL = false; route.TreatSenderAsLocalDomain = false; route.TreatRecipientAsLocalDomain = true; route.Save(); hMailServer.RouteAddresses addresses = route.Addresses; hMailServer.RouteAddress address1 = addresses.Add(); address1.Address = "*****@*****.**"; address1.Save(); hMailServer.RouteAddress address2 = addresses.Add(); address2.Address = "*****@*****.**"; address2.Save(); }
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 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 TestDeliverToExternalMimeRecipientsEnabledRouteAsExternal() { 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(); // Add a route so we can connect to localhost. hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(5, 250, false); route.TreatSecurityAsLocalDomain = false; route.Save(); hMailServer.Account userAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account recipientAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.Account catchallAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); _domain.Postmaster = catchallAccount.Address; _domain.Save(); hMailServer.FetchAccount fa = userAccount.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(recipientAccount1.Address, "test"); Assert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1); Utilities.AssertRecipientsInDeliveryQueue(0, false); }
public void TreatRecipientAsExternalDomain() { hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, 250, false); route.TreatRecipientAsLocalDomain = false; route.Save(); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); string result; Assert.IsFalse(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result)); Assert.IsTrue(result.Contains("530 SMTP authentication is required.")); }
public static hMailServer.Route AddRoutePointingAtLocalhostMultipleHosts(int numberOfTries) { // Add a route pointing at localhost hMailServer.Route route = AddRoutePointingAtLocalhost(numberOfTries, 250, false); route.DomainName = "dummy-example.com"; route.TargetSMTPHost = "localhost|localhost"; route.TargetSMTPPort = 250; route.NumberOfTries = numberOfTries; route.MinutesBetweenTry = 5; route.Save(); return(route); }
internal static hMailServer.Route AddRoutePointingAtLocalhost(int numberOfTries, int port) { // Add a route pointing at localhost hMailServer.Settings oSettings = SingletonProvider <Utilities> .Instance.GetApp().Settings; hMailServer.Route route = oSettings.Routes.Add(); route.DomainName = "example.com"; route.TargetSMTPHost = "localhost"; route.TargetSMTPPort = port; route.NumberOfTries = numberOfTries; route.MinutesBetweenTry = 5; route.Save(); return(route); }
public void TestDuplicateRoutes() { hMailServer.Application app = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.Routes routes = app.Settings.Routes; hMailServer.Route route = routes.Add(); route.DomainName = "test.com"; route.Save(); hMailServer.Route route2 = routes.Add(); route2.DomainName = "test.com"; route2.Save(); }
public void TestSenderAsLocalDomainSendToExternal() { hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, 250, false); route.TreatSenderAsLocalDomain = true; route.Save(); hMailServer.SecurityRange range = SingletonProvider <Utilities> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer"); range.RequireSMTPAuthLocalToExternal = true; range.Save(); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); string result; Assert.IsFalse(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result)); Assert.IsTrue(result.Contains("530 SMTP authentication is required.")); }
public bool SaveData() { if (_representedObject == null) { hMailServer.Settings settings = APICreator.Application.Settings; hMailServer.Routes routes = settings.Routes; _representedObject = routes.Add(); Marshal.ReleaseComObject(settings); Marshal.ReleaseComObject(routes); } _representedObject.DomainName = textDomainName.Text; _representedObject.Description = textDescription.Text; _representedObject.TargetSMTPHost = textTargetSMTPHost.Text; _representedObject.TargetSMTPPort = textTargetSMTPPort.Number; _representedObject.ConnectionSecurity = (eConnectionSecurity)comboConnectionSecurity.SelectedValue; _representedObject.TreatSenderAsLocalDomain = radioTreatSenderAsLocalDomain.Checked; _representedObject.TreatRecipientAsLocalDomain = radioTreatRecipientAsLocalDomain.Checked; _representedObject.NumberOfTries = textNumberOfTries.Number; _representedObject.MinutesBetweenTry = textNumberOfMinutesBetween.Number; _representedObject.RelayerRequiresAuth = checkServerRequiresAuth.Checked; _representedObject.RelayerAuthUsername = textUsername.Text; if (textPassword.Dirty) { _representedObject.SetRelayerAuthPassword(textPassword.Password); } _representedObject.AllAddresses = radioRouteForAll.Checked; _representedObject.Save(); // Set the object to clean. DirtyChecker.SetClean(this); Utility.RefreshNode(_representedObject.DomainName); return(true); }
internal hMailServer.Route AddRoutePointingAtLocalhostWithAuth(int numberOfTries, int port) { // Add a route pointing at localhost hMailServer.Settings oSettings = SingletonProvider <Utilities> .Instance.GetApp().Settings; hMailServer.Route route = oSettings.Routes.Add(); route.DomainName = "dummy-example.com"; route.TargetSMTPHost = "localhost"; route.TargetSMTPPort = port; route.NumberOfTries = numberOfTries; route.RelayerRequiresAuth = true; route.RelayerAuthUsername = GetUsername(); route.SetRelayerAuthPassword(GetPassword()); route.MinutesBetweenTry = 5; route.Save(); return(route); }
public void TestSenderAsExternalDomainSendToLocalAccountFail() { hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, 250, false); route.TreatSenderAsLocalDomain = false; route.Save(); hMailServer.SecurityRange range = SingletonProvider <Utilities> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer"); range.RequireSMTPAuthExternalToLocal = true; range.Save(); hMailServer.Account account1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); string result; Assert.IsFalse(oSMTP.Send("*****@*****.**", account1.Address, "Mail 1", "Mail 1", out result)); }
public void TestUseCaseDeliveryFromPrimaryMXToBackupMX() { hMailServer.Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, 250, false); route.TreatRecipientAsLocalDomain = true; route.TreatSenderAsLocalDomain = false; route.Save(); hMailServer.Account account1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); string result; Assert.IsTrue(oSMTP.Send("*****@*****.**", account1.Address, "Mail 1", "Mail 1", out result)); string text = POP3Simulator.AssertGetFirstMessageText(account1.Address, "test"); Assert.IsTrue(text.Contains("Mail 1")); }
public void TestRoute() { hMailServer.Settings oSettings = SingletonProvider <Utilities> .Instance.GetApp().Settings; hMailServer.Route route = oSettings.Routes.Add(); route.DomainName = "myroute.com"; route.TargetSMTPHost = "somehost.com"; route.TargetSMTPPort = 25; route.Save(); if (route.ID == 0) { throw new Exception("Route not saved properly"); } oSettings.Routes.DeleteByDBID(route.ID); }