Esempio n. 1
0
        public void TestPortInUse()
        {
            hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp();

            application.Stop();

            var serverSocket = new ServerSocket(1, 25);

            serverSocket.StartListen();

            application.Start();
            TCPSocket sock = new TCPSocket();

            // make sure it's possible to connect to the non blocked port.

            sock.CanConnect(110);
            sock.CanConnect(143);

            //let this our temp server die.
            sock.CanConnect(25);

            // make sure that hMailServer reported an error during start up because the ports were blocked.
            Utilities.AssertReportedError();

            // restart hMailServer again. everything is now back to normal.
            application.Stop();
            application.Start();
            sock.CanConnect(25);
        }
Esempio n. 2
0
        public void RestartServer()
        {
            hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp();

            for (int i = 0; i < 3; i++)
            {
                application.Stop();

                application.Start();
            }
        }
Esempio n. 3
0
        static internal void AskRestartServer()
        {
            if (MessageBox.Show(Strings.Localize("hMailServer needs to be restarted for the changes to take effect.") + Environment.NewLine +
                                Strings.Localize("Do you want to restart hMailServer now?"), EnumStrings.hMailServerAdministrator, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                using (new WaitCursor())
                {
                    hMailServer.Application application = APICreator.Application;
                    application.Stop();
                    application.Start();

                    MessageBox.Show(Strings.Localize("The hMailServer server has been restarted."), EnumStrings.hMailServerAdministrator, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Esempio n. 4
0
        private void buttonStartStop_Click(object sender, System.EventArgs e)
        {
            WaitCursor cursor = new WaitCursor();

            switch (_application.ServerState)
            {
            case eServerState.hStateRunning:
                _application.Stop();
                break;

            case eServerState.hStateStopped:
                _application.Start();
                break;
            }

            DisplayServerState();
        }
Esempio n. 5
0
        public bool SaveData()
        {
            if (_representedObject == null)
            {
                hMailServer.TCPIPPorts tcpIPPorts = APICreator.TCPIPPortsSettings;
                _representedObject = tcpIPPorts.Add();
                Marshal.ReleaseComObject(tcpIPPorts);
            }

            _representedObject.Address    = textIPAddress.Text;
            _representedObject.PortNumber = textTCPIPPort.Number;
            _representedObject.UseSSL     = checkEnableSSL.Checked;
            _representedObject.Protocol   = (hMailServer.eSessionType)comboProtocol.SelectedValue;

            if (comboSSLCertificate.SelectedValue == null)
            {
                _representedObject.SSLCertificateID = 0;
            }
            else
            {
                _representedObject.SSLCertificateID = (int)comboSSLCertificate.SelectedValue;
            }

            _representedObject.Save();

            DirtyChecker.SetClean(this);

            Utility.RefreshNode(InternalNames.GetPortName(_representedObject));

            if (MessageBox.Show(Strings.Localize("hMailServer needs to be restarted for the changes to take effect.") + Environment.NewLine +
                                Strings.Localize("Do you want to restart hMailServer now?"), EnumStrings.hMailServerAdministrator, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                using (new WaitCursor())
                {
                    hMailServer.Application application = APICreator.Application;
                    application.Stop();
                    application.Start();

                    MessageBox.Show(Strings.Localize("The hMailServer server has been restarted."), EnumStrings.hMailServerAdministrator, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            return(true);
        }
Esempio n. 6
0
        public void TestPortOpening()
        {
            hMailServer.Application oApp = SingletonProvider <Utilities> .Instance.GetApp();

            oApp.Settings.TCPIPPorts.SetDefault();

            SMTPClientSimulator pSMTPSimulator = new SMTPClientSimulator();
            POP3Simulator       pPOP3Simulator = new POP3Simulator();
            IMAPSimulator       pIMAPSimulator = new IMAPSimulator();

            oApp.Stop();

            hMailServer.TCPIPPorts oPorts = oApp.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();
            }

            oApp.Start();

            Assert.IsTrue(pSMTPSimulator.TestConnect(2500));
            Assert.IsTrue(pSMTPSimulator.TestConnect(11000));
            Assert.IsTrue(pSMTPSimulator.TestConnect(14300));

            oApp.Stop();

            hMailServer.TCPIPPort oPort = oApp.Settings.TCPIPPorts.Add();
            oPort.Protocol   = hMailServer.eSessionType.eSTSMTP;
            oPort.PortNumber = 25000;
            oPort.Save();

            oApp.Start();

            // Try to connect to the new port
            Assert.IsTrue(pSMTPSimulator.TestConnect(25000));

            oApp.Stop();

            // Delete the port again
            oApp.Settings.TCPIPPorts.DeleteByDBID(oPort.ID);

            // Change back the ports
            for (int i = 0; i < oPorts.Count; i++)
            {
                hMailServer.TCPIPPort oTestPort = oPorts[i];
                if (oTestPort.Protocol == hMailServer.eSessionType.eSTIMAP)
                {
                    oTestPort.PortNumber = 143;
                }
                else if (oTestPort.Protocol == hMailServer.eSessionType.eSTSMTP)
                {
                    oTestPort.PortNumber = 25;
                }
                else if (oTestPort.Protocol == hMailServer.eSessionType.eSTPOP3)
                {
                    oTestPort.PortNumber = 110;
                }

                oTestPort.Save();
            }

            oApp.Start();

            Assert.IsTrue(pSMTPSimulator.TestConnect(25));
            Assert.IsTrue(pPOP3Simulator.TestConnect(110));
            Assert.IsTrue(pPOP3Simulator.TestConnect(143));
        }
Esempio n. 7
0
        public hMailServer.Domain DoBasicSetup()
        {
            if (application.ServerState == hMailServer.eServerState.hStateStopped)
            {
                application.Start();
            }

            hMailServer.Domain domain = SingletonProvider <Utilities> .Instance.AddTestDomain();

            _settings.SecurityRanges.SetDefault();

            DisableSpamProtection();
            DisableVirusProtection();
            RemoveAllRoutes();
            RemoveAllRules();
            RemoveAllSharedFolders();
            RemoveAllGroups();
            ClearGreyListingWhiteAddresses();
            EnableLogging(true);


            _settings.SSLCertificates.Clear();
            _settings.TCPIPPorts.SetDefault();

            if (_settings.AutoBanOnLogonFailure)
            {
                _settings.AutoBanOnLogonFailure = false;
            }

            if (_settings.SMTPNoOfTries != 0)
            {
                _settings.SMTPNoOfTries = 0;
            }

            if (_settings.SMTPMinutesBetweenTry != 60)
            {
                _settings.SMTPMinutesBetweenTry = 60;
            }

            if (_settings.Scripting.Enabled != false)
            {
                _settings.Scripting.Enabled = false;
            }

            if (_settings.MirrorEMailAddress != "")
            {
                _settings.MirrorEMailAddress = "";
            }

            if (_settings.SMTPRelayer != "")
            {
                _settings.SMTPRelayer = "";
            }

            if (_settings.MaxDeliveryThreads != 50)
            {
                _settings.MaxDeliveryThreads = 50;
            }

            if (_settings.Scripting.Language != "VBScript")
            {
                _settings.Scripting.Language = "VBScript";
            }

            if (_settings.IMAPPublicFolderName != "#Public")
            {
                _settings.IMAPPublicFolderName = "#Public";
            }

            if (_settings.MaxNumberOfInvalidCommands != 3)
            {
                _settings.MaxNumberOfInvalidCommands = 3;
            }

            if (_settings.DisconnectInvalidClients != false)
            {
                _settings.DisconnectInvalidClients = false;
            }

            if (_settings.MaxSMTPRecipientsInBatch != 100)
            {
                _settings.MaxSMTPRecipientsInBatch = 100;
            }

            if (_settings.IMAPHierarchyDelimiter != ".")
            {
                _settings.IMAPHierarchyDelimiter = ".";
            }

            if (_settings.IMAPACLEnabled != true)
            {
                _settings.IMAPACLEnabled = true;
            }

            if (_settings.MaxMessageSize != 20480)
            {
                _settings.MaxMessageSize = 20480;
            }

            if (_settings.MaxNumberOfMXHosts != 15)
            {
                _settings.MaxNumberOfMXHosts = 15;
            }

            hMailServer.AntiVirus antiVirus = _settings.AntiVirus;

            if (antiVirus.ClamAVEnabled)
            {
                antiVirus.ClamAVEnabled = false;
            }

            if (antiVirus.ClamAVPort != 3310)
            {
                antiVirus.ClamAVPort = 3310;
            }

            if (antiVirus.ClamAVHost != "localhost")
            {
                antiVirus.ClamAVHost = "localhost";
            }

            EnableLogging(true);

            if (File.Exists(GetErrorLogFileName()))
            {
                string contents = File.ReadAllText(GetErrorLogFileName());
                Assert.Fail(contents);
            }

            if (File.Exists(GetEventLogFileName()))
            {
                File.Delete(GetEventLogFileName());
            }

            Utilities.AssertRecipientsInDeliveryQueue(0);

            return(domain);
        }
Esempio n. 8
0
 public void Start()
 {
     _object.Start();
 }