private void OnEditAddress() { if (listBoxAddresses.SelectedIndices.Count > 0) { EmailForm form = new EmailForm(); string old = listBoxAddresses.SelectedItems[0].ToString(); form.SetAddress(old); DialogResult r = form.ShowDialog(); if (r == DialogResult.OK) { string newAddress = form.GetAddress(); if (!IsEmailAddress(newAddress) && (newAddress != old)) { QMessageBox.ShowWarning("invalid email address!"); } else if (listBoxAddresses.Items.Contains(newAddress)) { QMessageBox.ShowWarning("email address existed!"); } else if (newAddress == old) { //Do Nothing } else { listBoxAddresses.Items.RemoveAt(listBoxAddresses.SelectedIndices[0]); listBoxAddresses.Items.Add(newAddress); } } } }
private void OnEditAccount() { if (listViewAccounts.SelectedItems.Count > 0) { ListViewItem item = listViewAccounts.SelectedItems[0]; EmailAccount a = (EmailAccount)item.Tag; AccountForm f = new AccountForm(a); while (f.ShowDialog() == DialogResult.OK) { string username = f.GetUsername(); if (string.IsNullOrEmpty(username)) { QMessageBox.ShowWarning("username can't be empty!"); } else if (!IsEmailAddress(username)) { QMessageBox.ShowWarning("email address is not valid!"); } else if (string.IsNullOrEmpty(f.GetPassword())) { QMessageBox.ShowWarning("password can't be empty!"); } else if (string.IsNullOrEmpty(f.GetNickname())) { QMessageBox.ShowWarning("nickname can't be empty!"); } else if (string.IsNullOrEmpty(f.GetServer())) { QMessageBox.ShowWarning("server can't be empty!"); } else { a.Username = f.GetUsername(); a.Password = f.GetPassword(); a.Nickname = f.GetNickname(); a.Server = f.GetServer(); a.Port = f.GetPort(); a.EnableSsl = f.EnabledSsl(); ShowAccount(item); listViewAccounts.Update(); BuildAccountsList(); break; } } } }
private void addAccountToolStripMenuItem_Click(object sender, EventArgs e) { AccountForm f = new AccountForm(); while (f.ShowDialog() == DialogResult.OK) { string username = f.GetUsername(); if (string.IsNullOrEmpty(username)) { QMessageBox.ShowWarning("username can't be empty!"); } else if (!IsEmailAddress(username)) { QMessageBox.ShowWarning("email address is not valid!"); } else if (string.IsNullOrEmpty(f.GetPassword())) { QMessageBox.ShowWarning("password can't be empty!"); } else if (string.IsNullOrEmpty(f.GetNickname())) { QMessageBox.ShowWarning("nickname can't be empty!"); } else if (string.IsNullOrEmpty(f.GetServer())) { QMessageBox.ShowWarning("server can't be empty!"); } else { EmailAccount a = f.GetAccount(); listViewAccounts.Items.Add(BuildListViewItem(a)); DataCenter.Instance.Add(a); BuildAccountsList(); break; } } }
private void addToolStripMenuItem_Click(object sender, EventArgs e) { EmailForm form = new EmailForm(); DialogResult r = form.ShowDialog(); if (r == DialogResult.OK) { string address = form.GetAddress(); if (!IsEmailAddress(address)) { QMessageBox.ShowWarning("invalid email address!"); } else if (listBoxAddresses.Items.Contains(address)) { QMessageBox.ShowWarning("email address existed!"); } else { listBoxAddresses.Items.Add(form.GetAddress()); } } }
private void buttonSend_Click(object sender, EventArgs e) { if (m_timer.Enabled)//表示timer正在工作 { m_timer.Stop(); m_timer.Enabled = false; OnDone(); return; } else if (backgroundWorkerMailSender.IsBusy) { backgroundWorkerMailSender.CancelAsync(); OnDone(); return; } if (comboBoxAccounts.Items.Count < 1) { QMessageBox.ShowWarning("account can not be empty!"); return; } else if (comboBoxAccounts.SelectedIndex < 0) { QMessageBox.ShowWarning("you must select an account!"); return; } else if (String.IsNullOrEmpty(textBoxSubject.Text)) { QMessageBox.ShowWarning("email subject can not be empty!"); return; } else if (String.IsNullOrEmpty(richTextBoxBody.Text)) { QMessageBox.ShowWarning("email body can not be empty!"); return; } else if (listBoxAddresses.Items.Count <= 0) { QMessageBox.ShowWarning("recipients can not be empty!"); return; } else { if (checkBoxTimedSend.Checked) { if (dateTimePickerTimedSend.Value <= DateTime.Now) { QMessageBox.ShowError("the time is in the past!"); return; } m_timer.Interval = dateTimePickerTimedSend.Value.Subtract(DateTime.Now).TotalSeconds * 1000; } else { m_timer.Interval = 1; } } WrappedItem item = (WrappedItem)comboBoxAccounts.SelectedItem; EmailAccount a = item.Account; a.Init(textBoxSubject.Text, richTextBoxBody.Text); object[] addresses = new object[listBoxAddresses.Items.Count]; listBoxAddresses.Items.CopyTo(addresses, 0); job = new MailJob(a, addresses); m_timer.Start(); buttonSend.Text = "Cancel"; buttonQuit.Enabled = false; this.Text = String.Format("{0} - waiting to send...", m_formText); }