Example #1
0
        public static void SetupSSLPorts(hMailServer.Application application, SslVersions sslVersions = null)
        {
            SSLCertificate sslCeritifcate = SetupSSLCertificate(application);

            var settings = application.Settings;

            var ports = settings.TCPIPPorts;

            ports.SetDefault();

            AddPort(ports, 25000, eConnectionSecurity.eCSNone, sslCeritifcate.ID, eSessionType.eSTSMTP);
            AddPort(ports, 11000, eConnectionSecurity.eCSNone, sslCeritifcate.ID, eSessionType.eSTPOP3);
            AddPort(ports, 14300, eConnectionSecurity.eCSNone, sslCeritifcate.ID, eSessionType.eSTIMAP);

            AddPort(ports, 25001, eConnectionSecurity.eCSTLS, sslCeritifcate.ID, eSessionType.eSTSMTP);
            AddPort(ports, 11001, eConnectionSecurity.eCSTLS, sslCeritifcate.ID, eSessionType.eSTPOP3);
            AddPort(ports, 14301, eConnectionSecurity.eCSTLS, sslCeritifcate.ID, eSessionType.eSTIMAP);

            AddPort(ports, 25002, eConnectionSecurity.eCSSTARTTLSOptional, sslCeritifcate.ID, eSessionType.eSTSMTP);
            AddPort(ports, 11002, eConnectionSecurity.eCSSTARTTLSOptional, sslCeritifcate.ID, eSessionType.eSTPOP3);
            AddPort(ports, 14302, eConnectionSecurity.eCSSTARTTLSOptional, sslCeritifcate.ID, eSessionType.eSTIMAP);

            AddPort(ports, 25003, eConnectionSecurity.eCSSTARTTLSRequired, sslCeritifcate.ID, eSessionType.eSTSMTP);
            AddPort(ports, 11003, eConnectionSecurity.eCSSTARTTLSRequired, sslCeritifcate.ID, eSessionType.eSTPOP3);
            AddPort(ports, 14303, eConnectionSecurity.eCSSTARTTLSRequired, sslCeritifcate.ID, eSessionType.eSTIMAP);

            settings.TlsVersion10Enabled = sslVersions == null || sslVersions.Tls10;
            settings.TlsVersion11Enabled = sslVersions == null || sslVersions.Tls11;
            settings.TlsVersion12Enabled = sslVersions == null || sslVersions.Tls12;
            settings.TlsVersion13Enabled = sslVersions == null || sslVersions.Tls13;

            application.Stop();
            application.Start();
        }
Example #2
0
        private static SSLCertificate SetupSSLCertificate(hMailServer.Application application)
        {
            var sslPath = GetSslCertPath();

            var exampleCert = Path.Combine(sslPath, "example.crt");
            var exampleKey  = Path.Combine(sslPath, "example.key");

            if (!File.Exists(exampleCert))
            {
                Assert.Fail("Certificate " + exampleCert + " was not found");
            }
            if (!File.Exists(exampleKey))
            {
                Assert.Fail("Private key " + exampleKey + " was not found");
            }


            SSLCertificate sslCertificate = application.Settings.SSLCertificates.Add();

            sslCertificate.Name            = "Example";
            sslCertificate.CertificateFile = exampleCert;
            sslCertificate.PrivateKeyFile  = exampleKey;
            sslCertificate.Save();

            return(sslCertificate);
        }
Example #3
0
        public static void SetupSSLPorts(hMailServer.Application application)
        {
            SSLCertificate sslCeritifcate = SetupSSLCertificate(application);

            var ports = application.Settings.TCPIPPorts;

            AddPort(ports, 25000, eConnectionSecurity.eCSNone, sslCeritifcate.ID, eSessionType.eSTSMTP);
            AddPort(ports, 11000, eConnectionSecurity.eCSNone, sslCeritifcate.ID, eSessionType.eSTPOP3);
            AddPort(ports, 14300, eConnectionSecurity.eCSNone, sslCeritifcate.ID, eSessionType.eSTIMAP);

            AddPort(ports, 25001, eConnectionSecurity.eCSTLS, sslCeritifcate.ID, eSessionType.eSTSMTP);
            AddPort(ports, 11001, eConnectionSecurity.eCSTLS, sslCeritifcate.ID, eSessionType.eSTPOP3);
            AddPort(ports, 14301, eConnectionSecurity.eCSTLS, sslCeritifcate.ID, eSessionType.eSTIMAP);

            AddPort(ports, 25002, eConnectionSecurity.eCSSTARTTLSOptional, sslCeritifcate.ID, eSessionType.eSTSMTP);
            AddPort(ports, 11002, eConnectionSecurity.eCSSTARTTLSOptional, sslCeritifcate.ID, eSessionType.eSTPOP3);
            AddPort(ports, 14302, eConnectionSecurity.eCSSTARTTLSOptional, sslCeritifcate.ID, eSessionType.eSTIMAP);

            AddPort(ports, 25003, eConnectionSecurity.eCSSTARTTLSRequired, sslCeritifcate.ID, eSessionType.eSTSMTP);
            AddPort(ports, 11003, eConnectionSecurity.eCSSTARTTLSRequired, sslCeritifcate.ID, eSessionType.eSTPOP3);
            AddPort(ports, 14303, eConnectionSecurity.eCSSTARTTLSRequired, sslCeritifcate.ID, eSessionType.eSTIMAP);

            application.Stop();
            application.Start();
        }
 // Domain activation or deactivation
 private static bool DomainActivate(string userName, string password, string domainName, bool active = true)
 {
     hMailServer.Application hMailApp = Authenticate(userName, password);
     hMailServer.Domain      myDomain = hMailApp.Domains.ItemByName[domainName];
     myDomain.Active = active;
     myDomain.Save();
     return(true);
 }
 // Delete account mailbox
 private static bool AccountDelete(string userName, string password, string domainName, string accountAddress)
 {
     hMailServer.Application hMailApp = Authenticate(userName, password);
     hMailServer.Domain      myDomain = hMailApp.Domains.ItemByName[domainName];
     hMailServer.Account     account  = myDomain.Accounts.ItemByAddress[accountAddress];
     myDomain.Accounts.DeleteByDBID(account.ID);
     return(true);
 }
 // Domain set catchall mailbox
 private static bool DomainActivateCatchAll(string userName, string password, string domainName, string mailboxEmail = "catchall", bool active = true)
 {
     hMailServer.Application hMailApp = Authenticate(userName, password);
     hMailServer.Domain      myDomain = hMailApp.Domains.ItemByName[domainName];
     myDomain.Active     = active;
     myDomain.Postmaster = mailboxEmail + "@" + domainName;
     myDomain.Save();
     return(true);
 }
 // Authenticate
 private static hMailServer.Application Authenticate(string userName, string password)
 {
     hMailServer.Application hMailApp = new hMailServer.Application();
     if (hMailApp != null)
     {
         hMailApp.Authenticate(userName, password);
     }
     return(hMailApp);
 }
 // Change Account mailbox password
 private static bool ChangAccountPassword(string userName, string password, string domainName, string accountAddress, string newPassword)
 {
     hMailServer.Application hMailApp = Authenticate(userName, password);
     hMailServer.Domain      myDomain = hMailApp.Domains.ItemByName[domainName];
     hMailServer.Account     account  = myDomain.Accounts.ItemByAddress[accountAddress];
     account.Password = newPassword;
     myDomain.Save();
     return(true);
 }
 // Deactivate account
 private static bool AccountActivate(string userName, string password, string domainName, string accountAddress, bool active = true)
 {
     hMailServer.Application hMailApp = Authenticate(userName, password);
     hMailServer.Domain      myDomain = hMailApp.Domains.ItemByName[domainName];
     hMailServer.Account     account  = myDomain.Accounts.ItemByAddress[accountAddress];
     account.Active = active;
     account.Save();
     return(true);
 }
Example #10
0
 // Create new domain
 private static bool DomainCreate(string user, string pass, string domainName)
 {
     hMailServer.Application hMailApp = Authenticate(user, pass);
     hMailServer.Domain      domain   = hMailApp.Domains.Add();
     domain.Name       = domainName;
     domain.Postmaster = "catchall@" + domainName; // add catch all address, mailbox
     domain.Active     = true;
     domain.Save();
     return(true);
 }
Example #11
0
        // Delete all accounts from domain
        private static bool DeleteAllAccounts(string userName, string password, string domainName)
        {
            hMailServer.Application hMailApp  = Authenticate(userName, password);
            hMailServer.Domain      myDomain  = hMailApp.Domains.ItemByName[domainName];
            hMailServer.Accounts    hAccounts = myDomain.Accounts;

            for (var account = 0; account < hAccounts.Count; account++)
            {
                var accountInfo = hAccounts.get_ItemByDBID(account);
                myDomain.Accounts.DeleteByDBID(accountInfo.ID);
            }
            return(true);
        }
Example #12
0
 public void registrarUsuario(String pUsuario, String pContraseƱa)
 {
     try
     {
         hMailServer.Application aplicacion = new hMailServer.Application();
         aplicacion.Authenticate("Administrador", "12345");
         var domain  = aplicacion.Domains.ItemByName["rubenabix.com"];
         var account = domain.Accounts.Add();
         account.Address  = pUsuario;
         account.Password = pContraseƱa;
         account.Active   = true;
         account.Save();
     }
     catch (Exception)
     {
     }
 }
Example #13
0
 // Create mailbox, Account: [email protected]
 private static bool AccountCreate(string userName, string password, string domainName, string accountAddress, string accountPassword, bool accountActive = true, int maxSize = 1000)
 {
     hMailServer.Application hMailApp = Authenticate(userName, password);
     hMailServer.Domain      myDomain = hMailApp.Domains.ItemByName[domainName];
     if (myDomain != null)
     {
         hMailServer.Account account = myDomain.Accounts.Add();
         account.Address  = accountAddress;
         account.Password = accountPassword;
         account.Active   = accountActive;
         account.MaxSize  = maxSize;
         account.Active   = true;
         account.Save();
         return(true);
     }
     else
     {
         return(false);
     }
 }