public static SystemSettings GetFileManagerSettings() { return(SystemController.GetSystemSettingsInternal(SystemSettings.FILEMANAGER_SETTINGS, false)); }
public static int SendMessage(string from, string to, string bcc, string subject, string body, MailPriority priority, bool isHtml, Attachment[] attachments) { // Command line argument must the the SMTP host. SmtpClient client = new SmtpClient(); // load SMTP client settings SystemSettings settings = SystemController.GetSystemSettingsInternal( SystemSettings.SMTP_SETTINGS, true ); client.Host = settings["SmtpServer"]; client.Port = settings.GetInt("SmtpPort"); if (!String.IsNullOrEmpty(settings["SmtpUsername"])) { client.Credentials = new NetworkCredential( settings["SmtpUsername"], settings["SmtpPassword"] ); } if (!String.IsNullOrEmpty(settings["SmtpEnableSsl"])) { client.EnableSsl = Utils.ParseBool(settings["SmtpEnableSsl"], false); } // create message MailMessage message = new MailMessage(from, to); message.Body = body; message.BodyEncoding = System.Text.Encoding.UTF8; message.IsBodyHtml = isHtml; message.Subject = subject; message.SubjectEncoding = System.Text.Encoding.UTF8; if (!String.IsNullOrEmpty(bcc)) { message.Bcc.Add(bcc); } message.Priority = priority; if (attachments != null) { foreach (Attachment current in attachments) { message.Attachments.Add(current); } } // send message try { client.Send(message); return(0); } catch (SmtpException ex) { switch (ex.StatusCode) { case SmtpStatusCode.BadCommandSequence: return(BusinessErrorCodes.SMTP_BAD_COMMAND_SEQUENCE); case SmtpStatusCode.CannotVerifyUserWillAttemptDelivery: return(BusinessErrorCodes.SMTP_CANNOT_VERIFY_USER_WILL_ATTEMPT_DELIVERY); case SmtpStatusCode.ClientNotPermitted: return(BusinessErrorCodes.SMTP_CLIENT_NOT_PERMITTED); case SmtpStatusCode.CommandNotImplemented: return(BusinessErrorCodes.SMTP_COMMAND_NOT_IMPLEMENTED); case SmtpStatusCode.CommandParameterNotImplemented: return(BusinessErrorCodes.SMTP_COMMAND_PARAMETER_NOT_IMPLEMENTED); case SmtpStatusCode.CommandUnrecognized: return(BusinessErrorCodes.SMTP_COMMAND_UNRECOGNIZED); case SmtpStatusCode.ExceededStorageAllocation: return(BusinessErrorCodes.SMTP_EXCEEDED_STORAGE_ALLOCATION); case SmtpStatusCode.GeneralFailure: return(BusinessErrorCodes.SMTP_GENERAL_FAILURE); case SmtpStatusCode.InsufficientStorage: return(BusinessErrorCodes.SMTP_INSUFFICIENT_STORAGE); case SmtpStatusCode.LocalErrorInProcessing: return(BusinessErrorCodes.SMTP_LOCAL_ERROR_IN_PROCESSING); case SmtpStatusCode.MailboxBusy: return(BusinessErrorCodes.SMTP_MAILBOX_BUSY); case SmtpStatusCode.MailboxNameNotAllowed: return(BusinessErrorCodes.SMTP_MAILBOX_NAME_NOTALLOWED); case SmtpStatusCode.MailboxUnavailable: return(BusinessErrorCodes.SMTP_MAILBOX_UNAVAILABLE); case SmtpStatusCode.MustIssueStartTlsFirst: return(BusinessErrorCodes.SMTP_MUST_ISSUE_START_TLS_FIRST); case SmtpStatusCode.ServiceClosingTransmissionChannel: return(BusinessErrorCodes.SMTP_SERVICE_CLOSING_TRANSMISSION_CHANNEL); case SmtpStatusCode.ServiceNotAvailable: return(BusinessErrorCodes.SMTP_SERVICE_NOT_AVAILABLE); case SmtpStatusCode.SyntaxError: return(BusinessErrorCodes.SMTP_SYNTAX_ERROR); case SmtpStatusCode.TransactionFailed: return(BusinessErrorCodes.SMTP_TRANSACTION_FAILED); case SmtpStatusCode.UserNotLocalTryAlternatePath: return(BusinessErrorCodes.SMTP_USER_NOT_LOCAL_TRY_ALTERNATE_PATH); case SmtpStatusCode.UserNotLocalWillForward: return(BusinessErrorCodes.SMTP_USER_NOT_LOCAL_WILL_FORWARD); default: return(BusinessErrorCodes.SMTP_UNKNOWN_ERROR); } } finally { // Clean up. message.Dispose(); } }
public override void DoWork() { BackgroundTask topTask = TaskManager.TopTask; // get input parameters string mailTo = (string)topTask.GetParamValue("MAIL_TO"); int auditLogSeverity = Utils.ParseInt((string)topTask.GetParamValue("AUDIT_LOG_SEVERITY"), -1); string auditLogSource = (string)topTask.GetParamValue("AUDIT_LOG_SOURCE"); string auditLogTask = (string)topTask.GetParamValue("AUDIT_LOG_TASK"); string auditLogDate = (string)topTask.GetParamValue("AUDIT_LOG_DATE"); int showExecutionLog = Utils.ParseInt((string)topTask.GetParamValue("SHOW_EXECUTION_LOG"), 0); // check input parameters if (String.IsNullOrEmpty(mailTo)) { TaskManager.WriteWarning("Specify 'Mail To' task parameter"); return; } string mailFrom = null; SystemSettings settings = SystemController.GetSystemSettingsInternal(SystemSettings.SMTP_SETTINGS, false); if (settings != null) { mailFrom = settings["SmtpUsername"]; } if (String.IsNullOrEmpty(mailFrom)) { TaskManager.WriteWarning("You need to configure SMTP settings first"); return; } DateTime logStart, logEnd; switch (auditLogDate) { case "today": logStart = DateTime.Now; logEnd = DateTime.Now; break; case "yesterday": logStart = DateTime.Now.AddDays(-1); logEnd = DateTime.Now.AddDays(-1); break; case "schedule": default: logEnd = DateTime.Now; ScheduleInfo schedule = SchedulerController.GetSchedule(topTask.ScheduleId); switch (schedule.ScheduleTypeId) { case "Daily": logStart = DateTime.Now.AddDays(-1); break; case "Weekly": logStart = DateTime.Now.AddDays(-7); break; case "Monthly": logStart = DateTime.Now.AddMonths(-1); break; case "Interval": logStart = DateTime.Now.AddSeconds(-schedule.Interval); break; case "OneTime": default: logStart = DateTime.Now; break; } break; } string mailSubject = "Audit Log Report (" + logStart.ToString("MMM dd, yyyy") + " - " + logEnd.ToString("MMM dd, yyyy") + ")"; StringBuilder sb = new StringBuilder(); sb.AppendLine("<html><head><style>"); sb.AppendLine("table, th, td { border: 1px solid black; border-collapse: collapse; }"); sb.AppendLine("th, td { padding: 5px; }"); sb.AppendLine("th { text-align: left; }"); sb.AppendLine("</style></head><body>"); sb.AppendLine("<h2>" + mailSubject + "</h2>"); sb.AppendFormat("<h3>Source: {0}, Task: {1}, Severity: {2}</h3>", String.IsNullOrEmpty(auditLogSource) ? "All" : auditLogSource, String.IsNullOrEmpty(auditLogTask) ? "All" : auditLogTask, GetAuditLogRecordSeverityName(auditLogSeverity)); DataTable logs = AuditLog.GetAuditLogRecordsPaged(topTask.EffectiveUserId, 0, 0, null, logStart, logEnd, auditLogSeverity, auditLogSource, auditLogTask, "", 0, Int32.MaxValue).Tables[1]; sb.AppendLine("<p>"); if (logs.Rows.Count == 0) { sb.AppendLine("Audit Log is empty."); } else { sb.AppendLine("<table>"); sb.Append("<tr><th>Started</th><th>Finished</th><th>Severity</th><th>Username</th><th>Source</th><th>Task</th><th>Item-Name</th>"); if (showExecutionLog == 1) { sb.AppendLine("<th>Execution-Log</th></tr>"); } else { sb.AppendLine("</tr>"); } foreach (DataRow log in logs.Rows) { sb.AppendLine("<tr>"); // Started sb.AppendFormat("<td>{0}</td>", log["StartDate"].ToString()); // Finished sb.AppendFormat("<td>{0}</td>", log["FinishDate"].ToString()); // Severity sb.AppendFormat("<td>{0}</td>", GetAuditLogRecordSeverityName((int)log["SeverityID"])); // Username sb.AppendFormat("<td>{0}</td>", log["Username"]); // Source sb.AppendFormat("<td>{0}</td>", log["SourceName"]); // Task sb.AppendFormat("<td>{0}</td>", log["TaskName"]); // Item-Name sb.AppendFormat("<td>{0}</td>", log["ItemName"]); // Execution-Log if (showExecutionLog == 1) { string executionLog = FormatPlainTextExecutionLog(log["ExecutionLog"].ToString()); sb.AppendFormat("<td>{0}</td>", executionLog); } sb.AppendLine("</tr>"); } sb.AppendLine("</table>"); } sb.AppendLine("</p></body></html>"); // send mail message int res = MailHelper.SendMessage(mailFrom, mailTo, mailSubject, sb.ToString(), true); if (res != 0) { TaskManager.WriteError("SMTP Error. Code: " + res.ToString()); } }