Exemple #1
0
        private void ButtonSendAsScheduled_Click(object sender, RoutedEventArgs e)
        {
            if (BodyTextEmpty())
            {
                MessageBox.Show("Mail body empty", "Error",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var scheduler = new MyScheduler();

            TimeSpan sendTime = scheduler.GetSendTime(timePicker.Text);

            if (sendTime == new TimeSpan())
            {
                MessageBox.Show("Incorrect date format", "Error",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            DateTime sendDateTime = (calendar.SelectedDate ?? DateTime.Today).Add(sendTime);

            if (sendDateTime < DateTime.Now)
            {
                MessageBox.Show("Date and time can't be earlier than now", "Error",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                tabControl.SelectedItem = tabItemMailEditor;
                return;
            }

            EmailSendServiceClass emailSender =
                new EmailSendServiceClass(comboBoxSenderSelect.Text, comboBoxSenderSelect.SelectedValue.ToString());

            scheduler.SendEmails(sendDateTime, emailSender, dataGridEmails.ItemsSource as IQueryable <Email>);
        }
Exemple #2
0
        private void ButtonSendImmediately_Click(object sender, RoutedEventArgs e)
        {
            if (BodyTextEmpty())
            {
                MessageBox.Show("Mail body empty", "Error",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                tabControl.SelectedItem = tabItemMailEditor;
                return;
            }

            string login    = comboBoxSenderSelect.Text;
            string password = comboBoxSenderSelect.SelectedValue.ToString();

            if (string.IsNullOrEmpty(login))
            {
                MessageBox.Show("Enter sender login", "Invalid input",
                                MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            if (string.IsNullOrEmpty(password))
            {
                MessageBox.Show("Enter sender password", "Invalid input",
                                MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            EmailSendServiceClass emailSender = new EmailSendServiceClass(login, password);

            emailSender.SendMails((IQueryable <Email>)dataGridEmails.ItemsSource);
        }
        /// <summary>
        //// Непосредственно отправка писем
        /// </summary>
        /// <param name="dtSend"></param>
        /// <param name="emailSender"></param>
        /// <param name="emails"></param>
        public void SendEmails(DateTime dateTimeSend, EmailSendServiceClass emailSender, IQueryable <Email> emails)
        {
            this.emailSender  = emailSender; // Экземпляр класса, отвечающего за отправку писем, присваиваем
            this.dateTimeSend = dateTimeSend;
            this.emails       = emails;

            timer.Tick    += Timer_Tick;
            timer.Interval = new TimeSpan(0, 0, 1);
            timer.Start();
        }