/// <summary> /// send Email method /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { try { using (var objProvider = new MailProvider()) { //create Email if (textBox8.Text == String.Empty || richTextBox2.Text == String.Empty) { throw new ArgumentNullException("Fill all fields!"); } //if selected node is Group Group objGroup = objProvider.GetGroup((int)treeView1.SelectedNode.Tag, treeView1.SelectedNode.Name); Receiver objReceiver = objProvider.GetReceiver((int)treeView1.SelectedNode.Tag, treeView1.SelectedNode.Name); if (objGroup != null) { foreach (var receiver in objGroup.Receivers) { var objEmail = new Email() { Receiver = receiver, Text = richTextBox2.Text, Header = textBox8.Text, SendingTime = DateTime.Now }; objProvider.AddEmail(objEmail); SendEmail(objEmail); } } //if receiver if (objReceiver != null) { var objEmail = new Email() { Receiver = objReceiver, Text = richTextBox2.Text, Header = textBox8.Text, SendingTime = DateTime.Now }; objProvider.AddEmail(objEmail); SendEmail(objEmail); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// add email to schedule /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button5_Click(object sender, EventArgs e) { try { if (textBox8.Text == String.Empty || richTextBox2.Text == String.Empty) { throw new ArgumentNullException("Fill all fileds"); } using (var objProvider = new MailProvider()) { var objEmail = new Email() { Header = textBox8.Text, Text = richTextBox2.Text, SendingTime = GetTime(), Sended = false, Receiver = objProvider.GetReceiver((int)treeView1.SelectedNode.Tag, treeView1.SelectedNode.Name) }; objProvider.AddEmail(objEmail); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }