// 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);
        }
Exemple #2
0
        public void TestSendToManyRecipients()
        {
            // Add distribution list
            hMailServer.Accounts accounts = _domain.Accounts;

            var recipients = new List <string>();

            for (int i = 0; i < 1000; i++)
            {
                hMailServer.Account account =
                    SingletonProvider <TestSetup> .Instance.AddAccount(accounts, string.Format("recipient{0}@test.com", i), "test");

                recipients.Add(account.Address);

                Marshal.ReleaseComObject(account);

                if (i % 10 == 0)
                {
                    TestTracer.WriteTraceInfo("Creating accounts: {0}/{1}", i, 1000);
                }
            }

            Marshal.ReleaseComObject(accounts);

            var sw = new Stopwatch();

            sw.Start();
            SmtpClientSimulator.StaticSend("*****@*****.**", recipients, "Test", "Test message");
            sw.Stop();

            Console.WriteLine("Elapsed time: " + sw.Elapsed.TotalSeconds);

            string dataDir =
                Path.Combine(SingletonProvider <TestSetup> .Instance.GetApp().Settings.Directories.DataDirectory, "test.com");

            // Check number of accounts.
            RetryHelper.TryAction(() =>
            {
                if (IsFolderCountReached(dataDir, 1000))
                {
                    return;
                }

                throw new Exception("Not enough files in folder yet.");
            }, TimeSpan.FromSeconds(5), TimeSpan.FromMinutes(2));
        }
Exemple #3
0
        public void TestSendToTooManyRecipients()
        {
            hMailServer.Accounts accounts = _domain.Accounts;
            SingletonProvider <TestSetup> .Instance.AddAccount(accounts, string.Format("*****@*****.**"), "test");

            var sock = new TcpConnection();

            sock.Connect(25);
            sock.ReadUntil("\r\n");
            string result;

            sock.Send("EHLO test.com\r\n");
            result = sock.ReadUntil("\r\n");
            Assert.IsTrue(result.StartsWith("250"));
            sock.Send("MAIL FROM: [email protected]\r\n");
            result = sock.ReadUntil("\r\n");
            Assert.IsTrue(result.StartsWith("250"));

            const int recipientCount = 51000;

            for (int i = 1; i <= recipientCount; i++)
            {
                string address = string.Format("test{0}@gmail.com", i);

                sock.Send(string.Format("RCPT TO: <{0}>\r\n", address));
                result = sock.ReadUntil("\r\n");
                if (i <= 50000)
                {
                    Assert.IsTrue(result.StartsWith("250"));
                }
                else
                {
                    Assert.IsFalse(result.StartsWith("250"));
                }

                if (i % 100 == 0)
                {
                    TestTracer.WriteTraceInfo("{0}/{1}", i, recipientCount);
                }
            }
        }