/// <summary> /// Executes the service process to check for delivery Confirmation /// </summary> /// <returns>True if process ran OK, False if there was an error</returns> public bool DeliveryServiceWork() { try { string emailAccount = string.Empty; string emailPassword = string.Empty; string emailDomain = string.Empty; SettingsModel model = new SettingsModel(_unitOfWork); string[] emailConfiguration = model.GetEmailConfiguration(); emailAccount = emailConfiguration[0]; emailPassword = emailConfiguration[1]; emailDomain = emailConfiguration[2]; using (mailUtility = new MailUtility(emailAccount, emailPassword, emailDomain)) { List<int> deliveredList = mailUtility.getEmailDeliveryConfirmation(); List<int> nonDeliveredList = mailUtility.GetEmailNonDeliveryConfirmation(); // Gets the list of pendingl emails IList<CS_Email> DeliveredEmails = ListEmailsById(deliveredList); foreach (CS_Email email in DeliveredEmails) { try { UpdateStatusEmail(email, Globals.EmailService.Status.ConfirmationReceived); } catch (Exception ex) { Logger.Write(string.Format("An error has ocurred while trying to update the Email with ID {0}!\n{1}\n{2}", email.ID, ex.InnerException, ex.StackTrace)); } } // Gets the list of nonDelivered emails IList<CS_Email> nonDeliveredEmails = ListEmailsById(nonDeliveredList); foreach (CS_Email email in nonDeliveredEmails) { try { UpdateStatusEmail(email, Globals.EmailService.Status.Error); } catch (Exception ex) { Logger.Write(string.Format("An error has ocurred while trying to update the Email with ID {0}!\n{1}\n{2}", email.ID, ex.InnerException, ex.StackTrace)); } } } } catch (Exception ex) { Logger.Write(string.Format("An error has ocurred while trying to confirm de delivery of the Emails!\n{0}\n{1}", ex.InnerException, ex.StackTrace)); // This process will not send any emails if there's an error, because it might be an exchange server problem return false; } return true; }