private void ListUsers() { EnableDomainsAndList(true); if (comboDomains.Items.Count == 0) { return; } listItems.Items.Clear(); int domainID = Convert.ToInt32(comboDomains.SelectedValue); hMailServer.Domain domain = APICreator.GetDomain(domainID); hMailServer.Accounts accounts = domain.Accounts; for (int i = 0; i < accounts.Count; i++) { hMailServer.Account account = accounts[i]; ListViewItem item = listItems.Items.Add(account.Address); item.Tag = account.ID; Marshal.ReleaseComObject(account); } Marshal.ReleaseComObject(accounts); Marshal.ReleaseComObject(domain); }
public void TestLargeDistributionList() { // Add distribution list hMailServer.Accounts accounts = _domain.Accounts; List <string> recipients = new List <string>(); for (int i = 0; i < 1000; i++) { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(accounts, string.Format("recipient{0}@test.com", i), "test"); recipients.Add(account.Address); Marshal.ReleaseComObject(account); } Marshal.ReleaseComObject(accounts); SingletonProvider <Utilities> .Instance.AddDistributionList(_domain, "*****@*****.**", recipients); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); SMTPSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Test", "Test message"); sw.Stop(); Console.WriteLine("Elapsed time: " + sw.Elapsed.TotalSeconds.ToString()); string dataDir = Path.Combine(SingletonProvider <Utilities> .Instance.GetApp().Settings.Directories.DataDirectory, "test.com"); // Check number of accounts. int secondsToWait = 60; while (secondsToWait > 0) { try { if (IsFolderCountReached(dataDir, 1000)) { break; } } catch (Exception) { } System.Threading.Thread.Sleep(10000); secondsToWait -= 5; } Assert.IsTrue(IsFolderCountReached(dataDir, 1000)); _domain.Delete(); Marshal.ReleaseComObject(_domain); }
public hMailServer.Account AddAccount(hMailServer.Accounts accounts, string sAddress, string sPassword) { hMailServer.Account oAccount = accounts.Add(); oAccount.Address = sAddress; oAccount.Password = sPassword; oAccount.Active = true; oAccount.Save(); return(oAccount); }
internal void OnAddADAccount(object sender, EventArgs e) { formActiveDirectoryAccounts accountsDlg = new formActiveDirectoryAccounts(); if (accountsDlg.ShowDialog() == DialogResult.OK) { hMailServer.Domain domain = APICreator.GetDomain(_domainID); hMailServer.Accounts accounts = domain.Accounts; Instances.MainForm.Cursor = Cursors.WaitCursor; string domainName = accountsDlg.DomainName; List <string> accountNames = accountsDlg.AccountNames; foreach (string accountName in accountNames) { try { hMailServer.Account account = accounts.Add(); account.IsAD = true; account.ADDomain = domainName; account.ADUsername = accountName; account.Active = true; string address = accountName; address = address.Replace(" ", "."); address = address + "@" + domain.Name; account.Address = address; account.Save(); Marshal.ReleaseComObject(account); } catch (Exception ex) { MessageBox.Show(ex.Message, EnumStrings.hMailServerAdministrator); } } Marshal.ReleaseComObject(domain); Marshal.ReleaseComObject(accounts); Instances.MainForm.Cursor = Cursors.Default; } IMainForm mainForm = Instances.MainForm; mainForm.RefreshCurrentNode(null); mainForm.ShowItem(mainForm.GetCurrentNode()); }
protected override void DeleteItems(List <ListViewItem> items) { hMailServer.Domain domain = APICreator.GetDomain(_domainID); hMailServer.Accounts accounts = domain.Accounts; foreach (ListViewItem item in items) { int accountID = Convert.ToInt32(item.Tag); accounts.DeleteByDBID(accountID); } Marshal.ReleaseComObject(domain); Marshal.ReleaseComObject(accounts); }
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)); }
protected override void LoadList() { listAccounts.Items.Clear(); hMailServer.Accounts accounts = representedDomain.Accounts; for (int i = 0; i < accounts.Count; i++) { hMailServer.Account account = accounts[i]; ListViewItem item = listAccounts.Items.Add(account.Address); item.SubItems.Add(EnumStrings.GetYesNoString(account.Active)); item.Tag = account; } }
public void TestSendViaSpamAssassin() { Utilities.AssertSpamAssassinIsRunning(); SingletonProvider <Utilities> .Instance.GetApp().Settings.AntiSpam.SpamAssassinEnabled = true; hMailServer.Accounts accounts = _domain.Accounts; hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(accounts, string.Format("*****@*****.**"), "test"); string dataDir = Path.Combine(SingletonProvider <Utilities> .Instance.GetApp().Settings.Directories.DataDirectory, "test.com"); string accountDir = Path.Combine(dataDir, "test"); int memoryUsage = Shared.GetCurrentMemoryUsage(); int maxMemoryUsage = memoryUsage + 2; const int numberOfMessages = 100; string executableName = Shared.GetExecutableName(); MailMessage mail = new MailMessage(); mail.From = new System.Net.Mail.MailAddress("*****@*****.**"); mail.To.Add("*****@*****.**"); mail.Subject = "Automatiskt servertest"; mail.Body = "Detta är ett automatiskt test av epostservern."; mail.BodyEncoding = System.Text.Encoding.GetEncoding(1252); mail.SubjectEncoding = System.Text.Encoding.GetEncoding(1252); for (int i = 0; i < numberOfMessages; i++) { SmtpClient oClient = new SmtpClient("localhost", 25); oClient.Send(mail); if (i % 5 == 0) { Shared.AssertLowMemoryUsage(maxMemoryUsage); } } WaitForFilesInFolder(accountDir, numberOfMessages, maxMemoryUsage); _domain.Delete(); }
public void TestSendToTooManyRecipients() { hMailServer.Accounts accounts = _domain.Accounts; hMailServer.Account senderAccount = SingletonProvider <Utilities> .Instance.AddAccount(accounts, string.Format("*****@*****.**"), "test"); List <string> recipients = new List <string>(); TCPSocket sock = new TCPSocket(); sock.Connect(25); string result = sock.ReadUntil("\r\n"); 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")); Stopwatch watch = new Stopwatch(); watch.Start(); for (int i = 0; i < 51000; 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 { long perfor = watch.ElapsedMilliseconds; Assert.IsFalse(result.StartsWith("250")); } } }
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); } } }
public void TestSendLargeBatch() { hMailServer.Accounts accounts = _domain.Accounts; hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(accounts, string.Format("*****@*****.**"), "test"); string dataDir = Path.Combine(SingletonProvider <Utilities> .Instance.GetApp().Settings.Directories.DataDirectory, "test.com"); string accountDir = Path.Combine(dataDir, "test"); int memoryUsage = Shared.GetCurrentMemoryUsage(); int maxMemoryUsage = memoryUsage + 5; const int numberOfMessages = 200000; for (int i = 0; i < numberOfMessages; i++) { Assert.IsTrue(SMTPSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Test", "Test message")); if (i % 100 == 0) { Shared.AssertLowMemoryUsage(maxMemoryUsage); } } // Check number of delivered messages. while (true) { if (GetNumberOfFilesInFolder(accountDir) == numberOfMessages) { break; } Shared.AssertLowMemoryUsage(maxMemoryUsage); System.Threading.Thread.Sleep(60 * 1000); } _domain.Delete(); }
protected override void LoadList() { listAccounts.Items.Clear(); hMailServer.Domain domain = APICreator.GetDomain(_domainID); hMailServer.Accounts accounts = domain.Accounts; for (int i = 0; i < accounts.Count; i++) { hMailServer.Account account = accounts[i]; ListViewItem item = listAccounts.Items.Add(account.Address); item.SubItems.Add(EnumStrings.GetYesNoString(account.Active)); item.Tag = account.ID; Marshal.ReleaseComObject(account); } Marshal.ReleaseComObject(domain); Marshal.ReleaseComObject(accounts); }
internal Accounts(hMailServer.Accounts o) { _object = o; }
public bool SaveData() { if (!ValidateForm()) { return(false); } bool newAccount = false; if (_representedAccount == null) { hMailServer.Domain domain = APICreator.GetDomain(_domainID); hMailServer.Accounts accounts = domain.Accounts; _representedAccount = accounts.Add(); Marshal.ReleaseComObject(accounts); Marshal.ReleaseComObject(domain); } if (_representedAccount.ID == 0) { newAccount = true; } _representedAccount.Address = textAddress.Text; _representedAccount.MaxSize = textMaxSize.Number; _representedAccount.Active = checkEnabled.Checked; _representedAccount.VacationMessageIsOn = checkVacationMessageEnable.Checked; _representedAccount.VacationSubject = textVacationMessageSubject.Text; _representedAccount.VacationMessage = textVacationMessageText.Text; _representedAccount.VacationMessageExpires = checkVacationMessageExpires.Checked; _representedAccount.VacationMessageExpiresDate = dateVacationMessageExpiresDate.FormattedValue; _representedAccount.ForwardEnabled = checkForwardEnabled.Checked; _representedAccount.ForwardAddress = textForwardAddress.Text; _representedAccount.ForwardKeepOriginal = checkForwardKeepOriginal.Checked; _representedAccount.SignatureEnabled = checkSignatureEnabled.Checked; _representedAccount.SignaturePlainText = textSignaturePlainText.Text; _representedAccount.SignatureHTML = textSignatureHTML.Text; _representedAccount.IsAD = checkAccountIsAD.Checked; _representedAccount.ADDomain = textADDomain.Text; _representedAccount.ADUsername = textADUsername.Text; _representedAccount.PersonFirstName = textFirstName.Text; _representedAccount.PersonLastName = textLastName.Text; _representedAccount.AdminLevel = (hMailServer.eAdminLevel)comboAdministrationLevel.SelectedValue; if (textPassword.Dirty) { _representedAccount.Password = textPassword.Password; } _representedAccount.Save(); // Refresh the node in the tree if the name has changed. IMainForm mainForm = Instances.MainForm; mainForm.RefreshCurrentNode(_representedAccount.Address); // Set the object to clean. DirtyChecker.SetClean(this); if (newAccount) { SearchNodeText crit = new SearchNodeText(_representedAccount.Address); mainForm.SelectNode(crit); } else { EnableDisable(); } return(true); }