public override void Run() { this.Info("Sending mails..."); try { foreach (FileInf mailFile in this.SelectFiles()) { XDocument xdoc = XDocument.Load(mailFile.Path); IEnumerable <XElement> xMails = xdoc.XPathSelectElements("Mails/Mail"); int count = 1; foreach (XElement xMail in xMails) { Mail mail = null; try { mail = Mail.Parse(xMail); } catch (ThreadAbortException) { throw; } catch (Exception e) { this.ErrorFormat("An error occured while parsing the mail {0}. Please check the XML configuration according to the documentation.", count); count++; continue; } try { mail.Send(this.Host, this.Port, this.EnableSsl, this.User, this.Password); this.InfoFormat("Mail {0} sent.", count); count++; } catch (ThreadAbortException) { throw; } catch (Exception e) { this.ErrorFormat("An error occured while sending the mail {0}. Error message: {1}", count, e.Message); } } } } catch (ThreadAbortException) { throw; } catch (Exception e) { this.ErrorFormat("An error occured while sending mails.", e); } this.Info("Task finished."); }
public override TaskStatus Run() { this.Info("Sending mails..."); bool success = true; bool atLeastOneSucceed = false; try { foreach (FileInf mailFile in this.SelectFiles()) { XDocument xdoc = XDocument.Load(mailFile.Path); IEnumerable <XElement> xMails = xdoc.XPathSelectElements("Mails/Mail"); int count = 1; foreach (XElement xMail in xMails) { Mail mail = null; try { mail = Mail.Parse(xMail); } catch (ThreadAbortException) { throw; } catch (Exception e) { this.ErrorFormat("An error occured while parsing the mail {0}. Please check the XML configuration according to the documentation.", count); success &= false; count++; continue; } try { mail.Send(this.Host, this.Port, this.EnableSsl, this.User, this.Password); this.InfoFormat("Mail {0} sent.", count); count++; success &= true; if (!atLeastOneSucceed) { atLeastOneSucceed = true; } } catch (ThreadAbortException) { throw; } catch (Exception e) { this.ErrorFormat("An error occured while sending the mail {0}. Error message: {1}", count, e.Message); success &= false; } } } } catch (ThreadAbortException) { throw; } catch (Exception e) { this.ErrorFormat("An error occured while sending mails.", e); success &= false; } Status status = Status.Success; if (!success && atLeastOneSucceed) { status = Status.Warning; } else if (!success) { status = Status.Error; } this.Info("Task finished."); return(new TaskStatus(status, false)); }
public override TaskStatus Run() { Info("Sending mails..."); bool success = true; bool atLeastOneSucceed = false; try { FileInf[] attachments = SelectAttachments(); foreach (FileInf mailFile in SelectFiles()) { var xdoc = XDocument.Load(mailFile.Path); var xMails = xdoc.XPathSelectElements("Mails/Mail"); int count = 1; foreach (XElement xMail in xMails) { Mail mail; try { mail = Mail.Parse(xMail, attachments); } catch (ThreadAbortException) { throw; } catch (Exception e) { ErrorFormat("An error occured while parsing the mail {0}. Please check the XML configuration according to the documentation. Error: {1}", count, e.Message); success = false; count++; continue; } try { mail.Send(Host, Port, EnableSsl, User, Password, IsBodyHtml); InfoFormat("Mail {0} sent.", count); count++; if (!atLeastOneSucceed) { atLeastOneSucceed = true; } } catch (ThreadAbortException) { throw; } catch (Exception e) { ErrorFormat("An error occured while sending the mail {0}. Error message: {1}", count, e.Message); success = false; } } } } catch (ThreadAbortException) { throw; } catch (Exception e) { ErrorFormat("An error occured while sending mails.", e); success = false; } var status = Status.Success; if (!success && atLeastOneSucceed) { status = Status.Warning; } else if (!success) { status = Status.Error; } Info("Task finished."); return(new TaskStatus(status, false)); }
private bool SendMails(ref bool atLeastOneSuccess) { var success = true; try { FileInf[] attachments = SelectAttachments(); foreach (FileInf mailFile in SelectFiles()) { var xdoc = XDocument.Load(mailFile.Path); var xMails = xdoc.XPathSelectElements("Mails/Mail"); int count = 1; foreach (XElement xMail in xMails) { Mail mail; try { mail = Mail.Parse(xMail, attachments); } catch (ThreadAbortException) { throw; } catch (Exception e) { ErrorFormat("An error occured while parsing the mail {0}. Please check the XML configuration according to the documentation. Error: {1}", count, e.Message); success = false; count++; continue; } try { mail.Send(Host, Port, EnableSsl, User, Password, IsBodyHtml); InfoFormat("Mail {0} sent.", count); count++; if (!atLeastOneSuccess) { atLeastOneSuccess = true; } } catch (ThreadAbortException) { throw; } catch (Exception e) { ErrorFormat("An error occured while sending the mail {0}. Error message: {1}", count, e.Message); success = false; } } } } catch (ThreadAbortException) { throw; } catch (Exception e) { ErrorFormat("An error occured while sending mails.", e); success = false; } return(success); }