/// <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;
        }
        public void SendEmail()
        {
            try
            {
                string pdfPath = _view.GetPDFReportFile();
                string[] emailConfiguration = _settingsModel.GetEmailConfiguration();
                string domain = _settingsModel.GetDomain();

                string fromEmail = _view.Username + "@" + domain;

                using (MailUtility mailUtil = new MailUtility(emailConfiguration[0], emailConfiguration[1], emailConfiguration[2]))
                {
                    mailUtil.SendUntrackMail(fromEmail,
                        _view.Receipts.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries),
                        null,
                        _view.Body,
                        _view.Subject,
                        new string[] { pdfPath });
                }
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("An error has ocurred while trying to send the Email!\n{0}\n{1}", ex.Message, ex.StackTrace));
                _view.DisplayMessage("An error ocurred while trying to send the Email.", false);
            }
        }
        /// <summary>
        /// Executes the service process to send emails
        /// </summary>
        /// <returns>True if process ran OK, False if there was an error</returns>
        public bool EmailServiceWork()
        {
            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))
                {

                    // Gets the list of pendingl emails
                    IList<CS_Email> pendingEmails = ListAllPendingEmails();
                    foreach (CS_Email email in pendingEmails)
                    {
                        try
                        {
                            bool emailed = mailUtility.SendEmail(email.Subject, email.Body, email.Receipts, "", email.ID);

                            if (emailed)
                                UpdateStatusEmail(email, Globals.EmailService.Status.Sent);
                        }
                        catch (Exception ex)
                        {
                            Logger.Write(string.Format("An error has ocurred while trying to send the Email with ID {0}!\n{1}\n{2}", email.ID, ex.InnerException, ex.StackTrace));
                            UpdateStatusEmail(email, Globals.EmailService.Status.Error);
                        }
                    }
                }

                return true;
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("An error has ocurred while trying to send 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;
            }
        }