public void SendMessages(string header, string body) { foreach (string mail in listStrMails) { using (MailMessage mm = new MailMessage(VariableClass.fromEmail, mail)) { mm.Subject = header; mm.Body = body; mm.IsBodyHtml = false; using (SmtpClient sc = new SmtpClient(VariableClass.smtpEmail, VariableClass.smtpPort)) { sc.EnableSsl = true; sc.Credentials = new NetworkCredential(VariableClass.fromEmail, strPassword); try { sc.Send(mm); SendEndWindow sew = new SendEndWindow(); sew.Show(); } catch (Exception ex) { WindowEr err = new WindowEr(); err.ErrorMessage("Невозможно отправить письмо" + ex.ToString()); err.Show(); } } } } }
private void btnSendEmail_Click(object sender, RoutedEventArgs e) { List <string> listStrMails = new List <string> { "*****@*****.**", "*****@*****.**" }; string strPassword = passwordBox.Password; foreach (string mail in listStrMails) { using (MailMessage mm = new MailMessage("*****@*****.**", mail)) { mm.Subject = "тестовое письмо"; mm.Body = "Mail Body"; mm.IsBodyHtml = false; using (SmtpClient sc = new SmtpClient("mielecas01.miele.net", 25)) { sc.EnableSsl = false; sc.Credentials = new NetworkCredential("*****@*****.**", strPassword); try { sc.Send(mm); MessageBox.Show("Письмо на адрес " + mail + " отправлено"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } } //MessageBox.Show("работа завершена"); SendEndWindow sew = new SendEndWindow(); sew.Show(); }