Exemplo n.º 1
0
 public void SendNewsletterAsync(int id)
 {
     AsyncManager.OutstandingOperations.Increment();
     Task.Factory.StartNew(() => {
         Newsletter newsletter = NewsletterServices.FindAllEntities(n => n.NewsletterId == id, null, "NewsletterTasks").FirstOrDefault();
         NewsletterInProcess(newsletter, true);
         NetworkCredential credentials = new NetworkCredential(BgResources.Email_UserName, BgResources.Email_Password);
         SmtpClient client             = new SmtpClient(BgResources.Email_Server, 25);
         client.EnableSsl   = BgResources.Email_SSL;
         client.Credentials = credentials;
         foreach (var task in newsletter.NewsletterTasks.ToList())
         {
             try
             {
                 MailMessage message = new MailMessage(BgResources.Email_UserName, task.Subscription.SubscriberEmail, task.Newsletter.Name, task.Newsletter.Html);
                 message.IsBodyHtml  = true;
                 client.Send(message);
                 NewsletterServices.DeleteNewsletterTask(task);
             }
             catch (SmtpException ex)
             {
                 task.Log = ex.Message;
                 NewsletterServices.UpdateNewsletterTask(task);
             }
         }
         NewsletterInProcess(newsletter, false);
         AsyncManager.OutstandingOperations.Decrement();
     });
 }
Exemplo n.º 2
0
 public ViewResult Details(int id)
 {
     return(View(NewsletterServices.FindAllEntities(n => n.NewsletterId == id, o => o.OrderByDescending(n => n.DateCreated), "NewsletterTasks").FirstOrDefault()));
 }