public void ProcessItem(EmailJobData jobItem)
 {
     var emailConnectionSettings = _connectionSettingsManager.Load<EmailConnectionSettings>(jobItem.SettingsSource, jobItem.SettingsKey);
     var emailServerSettings = new EmailServerSettings
     {
         Host = emailConnectionSettings.Host,
         Port = emailConnectionSettings.Port,
         UserName = emailConnectionSettings.UserName,
         Password = emailConnectionSettings.Password
     };
     string overrideEmailAddress = ConfigurationManager.AppSettings["OverrideAllEmailAddress"];
     var toAddressList = DataServiceMailAddress.ToMailAddressList(jobItem.ToAddressList);
     if (!string.IsNullOrWhiteSpace(overrideEmailAddress))
     {
         toAddressList = new List<MailAddress>()
         {
             new MailAddress(overrideEmailAddress)
         };
     }
     string subject = FilterSubject(jobItem.Subject);
     try
     {
         EmailAttachmentData[] attachments = null;
         if(jobItem.Attachments != null)
         {
             attachments = jobItem.Attachments.ToArray();
         }
         _emailSender.SendEmail(emailServerSettings, subject, jobItem.Body, toAddressList, jobItem.FromAddress.ToMailAddress(), attachments);
     }
     catch (RazorEngine.Templating.TemplateCompilationException ex)
     {
         var sb = new StringBuilder();
         sb.AppendLine("Error(s) compiling template for email: ");
         foreach (var item in ex.Errors)
         {
             sb.AppendLine("-" + item.Line.ToString() + ": " + item.ErrorText);
         }
         throw new Exception(sb.ToString(), ex);
     }
 }
        public void MarkItemFailed(EmailJobData jobData, Exception err)
        {
            jobData.FailureCount++;
            jobData.AddException(err);

            if(jobData.FailureCount > 3)
            {
                jobData.Status = EnumJobStatus.Error;
            }
            else 
            {
                jobData.Status = EnumJobStatus.New;
                jobData.QueuedDateTimeUtc = DateTime.UtcNow;
            }
            _documentSession.SaveChanges();
        }
 public void MarkItemSuccessful(EmailJobData jobData)
 {
     jobData.Status = EnumJobStatus.Complete;
     _documentSession.SaveChanges();
 }