public void threadOfMainSending(MessageMembers mb) { var thread = new Thread(new ParameterizedThreadStart(sendMail)); j.Show(); thread.Start(mb); }
public void testMail(object objMember) { MessageMembers mb = objMember as MessageMembers; TestSending ts = new TestSending(); ts.sendMail(mb); }
public override void sendMail(object objMember) { MessageMembers md = objMember as MessageMembers; try { if (md.Subject.Length == 0) { throw new EmptySubject(); } if (md.Body.Length == 0) { throw new EmptyBody(); } md.actBtnTest.Enabled = false; MailAddress from = new MailAddress(Data._EmailLogin, Data._CompanyName); SmtpClient smtp = new SmtpClient(Data._SmtpAddress, Data._SmtpPort); if (Data._EnableSSL) { smtp.EnableSsl = true; } smtp.Credentials = new NetworkCredential(Data._EmailLogin, Data._Password); MailAddress to = new MailAddress(Data._TestAddress); MailMessage message = new MailMessage(from, to); message.Subject = md.Subject; message.Body = md.Body; if (Data._EnableHTML) { message.IsBodyHtml = true; } smtp.Send(message); MessageBox.Show("Отправлено успешно на " + Data._TestAddress, "Тестовая отправка", MessageBoxButtons.OK); md.actBtnTest.Enabled = true; } catch (Exception exc) { if (exc is EmptySubject) { (exc as EmptySubject).ShowMessage(); } else if (exc is EmptyBody) { (exc as EmptyBody).ShowMessage(); } else { (exc as OwnExceptions).ShowMessage(); } } }
private void _view_mainSendingClick(object sender, EventArgs e) { MessageMembers mb = new MessageMembers(_view.Subject, _view.Body, null, null); _model.threadOfMainSending(mb); }
private void _view_testingSendingStrip(object sender, EventArgs e) { MessageMembers mb = new MessageMembers(_view.Subject, _view.Body, null, _view.actBtnTest); _model.threadOfTestSending(mb); }
public virtual void sendMail(object objMember) { MessageMembers mb = objMember as MessageMembers; try { if (mb.Subject.Length == 0) { throw new EmptySubject(); } if (mb.Body.Length == 0) { throw new EmptyBody(); } MailAddress from = new MailAddress(Data._EmailLogin, Data._CompanyName); SmtpClient smtp = new SmtpClient(Data._SmtpAddress, Data._SmtpPort); if (Data._EnableSSL) { smtp.EnableSsl = true; } smtp.Credentials = new NetworkCredential(Data._EmailLogin, Data._Password); ThreadPool.QueueUserWorkItem(delegate { for (int i = 0; i < Data._Destination.Count; i++) { if (isNotFirstLetter) { Thread.Sleep(Data._IntervalBetween * 1000); //соблюдать интервал между письмами, начиная со второго } MailAddress to = new MailAddress(Data._Destination[i]); MailMessage message = new MailMessage(from, to); message.Subject = mb.Subject; message.Body = mb.Body; if (Data._EnableHTML) { message.IsBodyHtml = true; } smtp.Send(message); isNotFirstLetter = true; //для thread.Sleep() выше (уже не первое письмо) */ j.Invoke((MethodInvoker)(() => j.addToList())); //не виснет, йоу } }); } catch (Exception exc) { if (exc is EmptyBody) { (exc as EmptyBody).ShowMessage(); } else if (exc is EmptySubject) { (exc as EmptySubject).ShowMessage(); } else { throw new OwnExceptions(); } } }
public void threadOfTestSending(MessageMembers mb) { var thread = new Thread(new ParameterizedThreadStart(testMail)); thread.Start(mb); }