private async void Button_Click(object sender, RoutedEventArgs e) { try { IMailService service = new SmtpService(); var model = new MailModel { From = tbFrom.Text, ToStr = tbTo.Text, Title = tbTitle.Text, Body = new TextRange( rtbBody.Document.ContentStart, rtbBody.Document.ContentEnd).Text, }; if (file != null) { model.Attachments.Add(new MailModel.Attachment { Name = FileName.Content.ToString(), Content = file }); } MessageBox.Show(await service.Send(model)); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void ThreadStart() { try { while (true) { Thread.Sleep(1000); try { lock (_emailToSend) { var emails = _emailToSend; _emailToSend = new List <Email>(); emails.AsParallel().ForAll(a => SmtpService.Send(a)); } } catch (Exception e) { _log.Error("Error during running send emails", e); } } } catch (Exception e) { _log.Error("Error during running send emails, outer", e); } }