Exemple #1
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            //if (dicDates.Count == 0)
            //{
            //    timer.Stop();
            //    MessageBox.Show("Письма отправлены.");
            //}
            //else if (dicDates.Keys.First<DateTime>().ToShortTimeString() == DateTime.Now.ToShortTimeString())
            //{
            //    emailSender.Body = dicDates[dicDates.Keys.First<DateTime>()];
            //    emailSender.Subject = $"Рассылка от {dicDates.Keys.First<DateTime>().ToShortTimeString()} ";
            //    emailSender.SendMails(emails);
            //    dicDates.Remove(dicDates.Keys.First<DateTime>());
            //}

            if (dtSend.ToShortTimeString() == DateTime.Now.ToShortTimeString())
            {
                emailSender.SendMails(emails);
                timer.Stop();
                MessageBox.Show("Письма отправлены.");
            }
        }
        /// <summary>
        /// Button to send mail right now.
        /// </summary>
        /// <param name="sender">Object.</param>
        /// <param name="e">Event.</param>
        private void btnSendAtOnce_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                strLogin    = cbSenderSelect.ComboBoxText;
                strPassword = cbSenderSelect.SelectedValue.ToString();
                strSmtp     = cbSmtpSelect.ComboBoxText;
                port        = (int)cbSmtpSelect.SelectedValue;
            }
            catch (Exception)
            {
                System.Windows.MessageBox.Show("Incorrect sender input!\n Please, try again. ");
                return;
            }


            doc = new TextRange(rtbMailBody.Document.ContentStart, rtbMailBody.Document.ContentEnd);
            if (string.IsNullOrEmpty(strLogin) || string.IsNullOrEmpty(strPassword))
            {
                System.Windows.MessageBox.Show("Выберите отправителя");
                return;
            }
            if (string.IsNullOrEmpty(cbSmtpSelect.Text))
            {
                System.Windows.MessageBox.Show("Выберите smtp-сервер");
                return;
            }
            if (IsRichTextBoxEmpty(rtbMailBody))
            {
                System.Windows.MessageBox.Show("Не указан текст письма");
                tabMailBody.IsSelected = true;
                return;
            }
            EmailSendService emailSender = new EmailSendService(strLogin, strPassword, strSmtp, port);

            emailSender.SendMails((IQueryable <Email>)dgEmails.ItemsSource);
        }