public ucIPRange(int securityRangeID) { InitializeComponent(); if (securityRangeID > 0) { hMailServer.SecurityRanges securityRanges = APICreator.SecurityRanges; try { _representedObject = securityRanges.get_ItemByDBID(securityRangeID); } catch (Exception) { MessageBox.Show(Strings.Localize("The IP range does not exist."), EnumStrings.hMailServerAdministrator,MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.Enabled = false; } Marshal.ReleaseComObject(securityRanges); } DirtyChecker.SubscribeToChange(this, OnContentChanged); new TabOrderManager(this).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); dateTimeExpiresTime.Value = DateTime.Now; EnableDisable(); }
public ucIPRange(int securityRangeID) { InitializeComponent(); if (securityRangeID > 0) { hMailServer.SecurityRanges securityRanges = APICreator.SecurityRanges; try { _representedObject = securityRanges.get_ItemByDBID(securityRangeID); } catch (Exception) { MessageBox.Show(Strings.Localize("The IP range does not exist."), EnumStrings.hMailServerAdministrator, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.Enabled = false; } Marshal.ReleaseComObject(securityRanges); } DirtyChecker.SubscribeToChange(this, OnContentChanged); new TabOrderManager(this).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); dateTimeExpiresTime.Value = DateTime.Now; EnableDisable(); }
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 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 TestBlockingDeliveries() { hMailServer.SecurityRange range = SingletonProvider <Utilities> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer"); range.RequireSMTPAuthLocalToLocal = false; range.RequireSMTPAuthLocalToExternal = false; range.RequireSMTPAuthExternalToLocal = false; range.RequireSMTPAuthExternalToExternal = false; range.AllowDeliveryFromLocalToLocal = false; range.AllowDeliveryFromLocalToRemote = false; range.AllowDeliveryFromRemoteToLocal = false; range.AllowDeliveryFromRemoteToRemote = false; range.Save(); hMailServer.Account account1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); string result1, result2, result3, result4; Assert.IsFalse(oSMTP.Send(account1.Address, account1.Address, "Mail 1", "Mail 1", out result1)); Assert.IsFalse(oSMTP.Send(account1.Address, "*****@*****.**", "Mail 1", "Mail 1", out result2)); Assert.IsFalse(oSMTP.Send("*****@*****.**", account1.Address, "Mail 1", "Mail 1", out result3)); Assert.IsFalse(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result4)); Assert.IsTrue(result1.Contains("550 Delivery is not allowed to this address.")); Assert.IsTrue(result2.Contains("550 Delivery is not allowed to this address.")); Assert.IsTrue(result3.Contains("550 Delivery is not allowed to this address.")); Assert.IsTrue(result4.Contains("550 Delivery is not allowed to this address.")); }
public void TestSaveValidIPRange() { hMailServer.Application app = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.SecurityRange range = app.Settings.SecurityRanges.Add(); range.Name = "Test"; range.LowerIP = "0.0.0.0"; range.UpperIP = "0.0.0.1"; range.Save(); }
public void TestSMTPAuthLocalToExternal() { hMailServer.SecurityRange range = SingletonProvider <Utilities> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer"); range.RequireSMTPAuthLocalToExternal = 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)); Assert.IsTrue(result.Contains("SMTP authentication is required")); }
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.")); }
private void AddIPRange() { hMailServer.SecurityRange oRange = _ipRanges.Add(); oRange.LowerIP = "127.0.0.1"; oRange.UpperIP = "127.0.0.1"; oRange.Name = "My computer"; oRange.AllowDeliveryFromLocalToLocal = true; oRange.AllowDeliveryFromLocalToRemote = true; oRange.AllowDeliveryFromRemoteToLocal = true; oRange.AllowIMAPConnections = true; oRange.AllowPOP3Connections = true; oRange.AllowSMTPConnections = true; oRange.EnableSpamProtection = true; oRange.Save(); }
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 TestSMTPAuthExternalToLocal() { 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(); Assert.IsFalse(oSMTP.Send("*****@*****.**", account1.Address, "Mail 1", "Mail 1")); range.RequireSMTPAuthExternalToLocal = false; range.Save(); Assert.IsTrue(oSMTP.Send("*****@*****.**", account1.Address, "Mail 1", "Mail 1")); Utilities.AssertRecipientsInDeliveryQueue(0); }
public void TestSMTPAuthExternalToExternal() { hMailServer.SecurityRange range = SingletonProvider <Utilities> .Instance.GetApp().Settings.SecurityRanges.get_ItemByName("My computer"); range.RequireSMTPAuthExternalToExternal = true; range.Save(); SMTPClientSimulator oSMTP = new SMTPClientSimulator(); string result; Assert.IsFalse(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result)); Assert.IsTrue(result.Contains("SMTP authentication is required.")); range.RequireSMTPAuthExternalToExternal = false; range.AllowDeliveryFromRemoteToRemote = false; range.Save(); Assert.IsFalse(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1", out result)); Assert.IsTrue(result.Contains("550 Delivery is not allowed to this address.")); }
protected override void LoadList() { listObjects.Items.Clear(); hMailServer.Application app = APICreator.Application; hMailServer.SecurityRanges securityRanges = APICreator.SecurityRanges; for (int i = 0; i < securityRanges.Count; i++) { hMailServer.SecurityRange securityRange = securityRanges[i]; ListViewItem item = listObjects.Items.Add(securityRange.Name); item.SubItems.Add(securityRange.LowerIP); item.SubItems.Add(securityRange.UpperIP); item.SubItems.Add(securityRange.Priority.ToString()); if (securityRange.Expires) { item.SubItems.Add(securityRange.ExpiresTime.ToString()); item.ForeColor = Color.Red; } else { item.SubItems.Add(""); } item.Tag = securityRange.ID; Marshal.ReleaseComObject(securityRange); } Marshal.ReleaseComObject(securityRanges); }
public bool SaveData() { bool newObject = false; if (_representedObject == null) { hMailServer.Application app = APICreator.Application; hMailServer.Settings settings = app.Settings; hMailServer.SecurityRanges securityRanges = settings.SecurityRanges; _representedObject = securityRanges.Add(); newObject = true; Marshal.ReleaseComObject(settings); Marshal.ReleaseComObject(securityRanges); } _representedObject.Name = textName.Text; _representedObject.Priority= textPriority.Number; _representedObject.LowerIP = textLowerIPAddress.Text; _representedObject.UpperIP = textUpperIPAddress.Text; _representedObject.AllowSMTPConnections = checkAllowSMTP.Checked; _representedObject.AllowPOP3Connections = checkAllowPOP3.Checked; _representedObject.AllowIMAPConnections = checkAllowIMAP.Checked; _representedObject.RequireSMTPAuthLocalToLocal = checkRequireSMTPAuthLocalToLocal.Checked; _representedObject.RequireSMTPAuthLocalToExternal = checkRequireSMTPAuthLocalToExternal.Checked; _representedObject.RequireSMTPAuthExternalToLocal = checkRequireSMTPAuthExternalToLocal.Checked; _representedObject.RequireSMTPAuthExternalToExternal = checkRequireSMTPAuthExternalToExternal.Checked; _representedObject.AllowDeliveryFromLocalToLocal = checkAllowDeliveiesFromL2L.Checked; _representedObject.AllowDeliveryFromLocalToRemote = checkAllowDeliveiesFromL2R.Checked; _representedObject.AllowDeliveryFromRemoteToLocal = checkAllowDeliveiesFromR2L.Checked; _representedObject.AllowDeliveryFromRemoteToRemote = checkAllowDeliveiesFromR2R.Checked; _representedObject.EnableSpamProtection = checkSpamProtection.Checked; _representedObject.EnableAntiVirus = checkAntiVirus.Checked; _representedObject.Expires = checkExpires.Checked; _representedObject.ExpiresTime = dateTimeExpiresTime.Value; try { _representedObject.Save(); } catch (Exception e) { MessageBox.Show(e.Message, EnumStrings.hMailServerAdministrator, MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } // Refresh the node in the tree if the name has changed. IMainForm mainForm = Instances.MainForm; mainForm.RefreshCurrentNode(checkExpires.Checked ? Color.Red : Color.Black, textName.Text); // Set the object to clean. DirtyChecker.SetClean(this); if (newObject) { SearchNodeText crit = new SearchNodeText(_representedObject.Name); mainForm.SelectNode(crit); } return true; }
private void DisplayWarnings() { listWarnings.Items.Clear(); hMailServer.Settings settings = APICreator.Application.Settings; if (settings.HostName.Length == 0) { AddWarning("W001", Strings.Localize("High"), Strings.Localize("You haven't specified the public host name for this computer in the SMTP settings.")); } if (settings.DenyMailFromNull) { AddWarning("W002", Strings.Localize("High"), Strings.Localize("You have configured hMailServer not to allow email with empty sender address. Many email server will not accept email from your server with this configuration.")); } int autobanRanges = 0; // Check if External to external is enabled in any of the IP ranges. hMailServer.SecurityRanges ranges = settings.SecurityRanges; for (int i = 0; i < ranges.Count; i++) { hMailServer.SecurityRange range = ranges[i]; if (range.AllowDeliveryFromRemoteToRemote && !range.RequireSMTPAuthExternalToExternal) { string warning = Strings.Localize("hMailServer is configured to allow deliveries from external to external accounts in the IP range %s. This may make the server vulnerable to spam. It is recommended that you disable this option."); warning = warning.Replace("%s", range.Name); AddWarning("W003", Strings.Localize("Critical"), warning); } if (range.LowerIP == "127.0.0.1" && range.UpperIP == "127.0.0.1" && range.Expires) { string warning = Strings.Localize("Localhost is currently banned in the IP ranges."); AddWarning("W004", Strings.Localize("High"), warning); } if (range.Expires) { autobanRanges += 1; } Marshal.ReleaseComObject(range); } if (autobanRanges > 0) { string warning = Strings.Localize("There is a total of %s auto-ban IP ranges."); warning = warning.Replace("%s", autobanRanges.ToString()); AddWarning("W005", Strings.Localize("Medium"), warning); } Marshal.ReleaseComObject(ranges); Marshal.ReleaseComObject(settings); }
public bool SaveData() { bool newObject = false; if (_representedObject == null) { hMailServer.Application app = APICreator.Application; hMailServer.Settings settings = app.Settings; hMailServer.SecurityRanges securityRanges = settings.SecurityRanges; _representedObject = securityRanges.Add(); newObject = true; Marshal.ReleaseComObject(settings); Marshal.ReleaseComObject(securityRanges); } _representedObject.Name = textName.Text; _representedObject.Priority = textPriority.Number; _representedObject.LowerIP = textLowerIPAddress.Text; _representedObject.UpperIP = textUpperIPAddress.Text; _representedObject.AllowSMTPConnections = checkAllowSMTP.Checked; _representedObject.AllowPOP3Connections = checkAllowPOP3.Checked; _representedObject.AllowIMAPConnections = checkAllowIMAP.Checked; _representedObject.RequireSMTPAuthLocalToLocal = checkRequireSMTPAuthLocalToLocal.Checked; _representedObject.RequireSMTPAuthLocalToExternal = checkRequireSMTPAuthLocalToExternal.Checked; _representedObject.RequireSMTPAuthExternalToLocal = checkRequireSMTPAuthExternalToLocal.Checked; _representedObject.RequireSMTPAuthExternalToExternal = checkRequireSMTPAuthExternalToExternal.Checked; _representedObject.AllowDeliveryFromLocalToLocal = checkAllowDeliveiesFromL2L.Checked; _representedObject.AllowDeliveryFromLocalToRemote = checkAllowDeliveiesFromL2R.Checked; _representedObject.AllowDeliveryFromRemoteToLocal = checkAllowDeliveiesFromR2L.Checked; _representedObject.AllowDeliveryFromRemoteToRemote = checkAllowDeliveiesFromR2R.Checked; _representedObject.EnableSpamProtection = checkSpamProtection.Checked; _representedObject.EnableAntiVirus = checkAntiVirus.Checked; _representedObject.Expires = checkExpires.Checked; _representedObject.ExpiresTime = dateTimeExpiresTime.Value; try { _representedObject.Save(); } catch (Exception e) { MessageBox.Show(e.Message, EnumStrings.hMailServerAdministrator, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } // Refresh the node in the tree if the name has changed. IMainForm mainForm = Instances.MainForm; mainForm.RefreshCurrentNode(checkExpires.Checked ? Color.Red : Color.Black, textName.Text); // Set the object to clean. DirtyChecker.SetClean(this); if (newObject) { SearchNodeText crit = new SearchNodeText(_representedObject.Name); mainForm.SelectNode(crit); } return(true); }