Ejemplo n.º 1
0
        /// <summary>
        /// Таймер
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Timer_Tick(object sender, EventArgs e)
        {
            if (dtSend.ToShortTimeString() == DateTime.Now.ToShortTimeString())
            {
                List <string> listEmails = new List <string>();
                foreach (Emails em in emails)
                {
                    listEmails.Add(em.Value);
                }

                emailSender.SendMails(WpfMailSender.MailSubject, WpfMailSender.MailBody, listEmails);
                timer.Stop();
                MessageBox.Show("Отправка писем завершена");
            }
        }
Ejemplo n.º 2
0
        private void BtnSendAtOnce_Click(object sender, RoutedEventArgs e)
        {
            string strLogin    = cbSenderSelect.Text;
            string strPassword = txtbxPassword.Password;

            //string strPassword = cbSenderSelect.SelectedValue.ToString();

            if (string.IsNullOrEmpty(strLogin))
            {
                MessageBox.Show("Выберите отправителя");
                return;
            }

            if (string.IsNullOrEmpty(strPassword))
            {
                MessageBox.Show("Укажите пароль отправителя");
                return;
            }

            if (txtbxSubject.Text == "" || txtbxBody.Text == "")
            {
                MessageBox.Show("Заголовок и тело письма не должны быть пустыми");
                tabControl.SelectedItem = tbitmMail;
                return;
            }

            List <string> listEmails = new List <string>();

            foreach (Emails em in dgEmails.ItemsSource)
            {
                listEmails.Add(em.Value);
            }

            WpfEmailSendService emailSender = new WpfEmailSendService(strLogin, strPassword);

            emailSender.ShowMessage += msg => MessageBox.Show(msg);

            //emailSender.SmtpServer = cbSmtpServer.Text;
            emailSender.SmtpServer = txtbxSmtpServer.Text;
            emailSender.SmtpPort   = (from f in DBClass.SmtpServers
                                      where f.Server == txtbxSmtpServer.Text
                                      select f.Port).ToList <int>()[0];

            emailSender.SendMails(MailSubject, MailBody, listEmails);
            MessageBox.Show("Отправка писем завершена");
        }