Ejemplo n.º 1
0
        /// <summary>
        /// Button to send mail on date.
        /// </summary>
        /// <param name="sender">Object.</param>
        /// <param name="e">Event.</param>
        private void btnSendOnDate_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;
            }

            Scheduler sc         = new Scheduler();
            TimeSpan  tsSendTime = sc.GetSendTime(tbTimePicker.Text);

            if (tsSendTime == new TimeSpan())
            {
                System.Windows.MessageBox.Show("Некорректный формат даты");
                return;
            }
            DateTime dtSendDateTime = (cldSchedulDateTimes.SelectedDate ?? DateTime.Today).Add(tsSendTime);

            if (dtSendDateTime < DateTime.Now)
            {
                System.Windows.MessageBox.Show("Дата и время отправки писем не могут быть раньше, чем настоящее время");
                return;
            }
            EmailSendService emailSender = new EmailSendService(strLogin, strPassword, strSmtp, port);

            sc.SendEmails(dtSendDateTime, emailSender, (IQueryable <Email>)dgEmails.ItemsSource);
        }
Ejemplo n.º 2
0
        /// <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);
        }