Add admin emailing
This commit is contained in:
@@ -15,7 +15,12 @@ namespace LeafWeb.Web.Services
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private readonly string _emaialFromAddress;
|
||||
private readonly string _emailFromAddress;
|
||||
|
||||
/// <summary>
|
||||
/// Comma separated values
|
||||
/// </summary>
|
||||
private readonly string _adminEmailAddresses;
|
||||
|
||||
private readonly SmtpClient _smtpClient;
|
||||
|
||||
@@ -35,7 +40,8 @@ namespace LeafWeb.Web.Services
|
||||
ConfigurationManager.AppSettings["SmtpPassword"]
|
||||
);
|
||||
|
||||
_emaialFromAddress = ConfigurationManager.AppSettings["EmailFromAddress"];
|
||||
_emailFromAddress = ConfigurationManager.AppSettings["EmailFromAddress"];
|
||||
_adminEmailAddresses = ConfigurationManager.AppSettings["AdminEmailAddresses"];
|
||||
}
|
||||
|
||||
public EmailNotificationService() : this(new DataService())
|
||||
@@ -52,6 +58,12 @@ namespace LeafWeb.Web.Services
|
||||
SendLeafWebSuccess(leafInput);
|
||||
}
|
||||
|
||||
public void SendAdministratorMessage(string subject, string body)
|
||||
{
|
||||
var message = new MailMessage(_emailFromAddress, _adminEmailAddresses, subject, body);
|
||||
SendMessage(message);
|
||||
}
|
||||
|
||||
private void SendLeafWebSuccess(LeafInput leafInput)
|
||||
{
|
||||
var fileStreams =
|
||||
@@ -65,7 +77,7 @@ namespace LeafWeb.Web.Services
|
||||
|
||||
body += "Please see the attached results.";
|
||||
|
||||
var message = new MailMessage(_emaialFromAddress, leafInput.Email, "LeafWeb results", body);
|
||||
var message = new MailMessage(_emailFromAddress, leafInput.Email, "LeafWeb results", body);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -97,7 +109,7 @@ namespace LeafWeb.Web.Services
|
||||
|
||||
body += FormatWarningMessage(leafInput);
|
||||
|
||||
var message = new MailMessage(_emaialFromAddress, leafInput.Email, "LeafWeb processing error", body);
|
||||
var message = new MailMessage(_emailFromAddress, leafInput.Email, "LeafWeb processing error", body);
|
||||
SendMessage(message);
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,12 @@ namespace LeafWeb.Web.Services
|
||||
}
|
||||
catch (PiscalClientException ex)
|
||||
{
|
||||
logger.Error("LeafInputFile: {0}, ProcessQueue Exception: {1}", pending.Id, ex.Message);
|
||||
var errorMessage =
|
||||
$"LeafInputFile: {pending.Id}\r\nProcessRunning Exception: {ex.Message}"
|
||||
+ $"\r\nInnerException: {ex.InnerException}\r\nStackTrace: {ex.StackTrace}";
|
||||
logger.Error(errorMessage);
|
||||
BackgroundJob.Enqueue(() => _emailService.SendAdministratorMessage("LeafWeb ProcessQueue Exception", errorMessage));
|
||||
|
||||
_dataService.SetLeafInputStatus(pending, LeafInputStatusType.Exception, "Error occurred starting LeafInput", ex.Message);
|
||||
logger.Info("LeafInputFile: {0}, Cleanup", pending.Id);
|
||||
_piscalService.Cleanup(pending);
|
||||
@@ -140,7 +145,12 @@ namespace LeafWeb.Web.Services
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error("LeafInputFile: {0}, ProcessRunning Exception: {1}\r\n{2}\r\n{3}", leafInput.Id, ex.Message, ex.InnerException, ex.StackTrace);
|
||||
var errorMessage =
|
||||
$"LeafInputFile: {leafInput.Id}\r\nProcessRunning Exception: {ex.Message}"
|
||||
+ $"\r\nInnerException: {ex.InnerException}\r\nStackTrace: {ex.StackTrace}";
|
||||
logger.Error(errorMessage);
|
||||
BackgroundJob.Enqueue(() => _emailService.SendAdministratorMessage("LeafWeb ProcessRunning Exception", errorMessage));
|
||||
|
||||
_dataService.SetLeafInputStatus(leafInput, LeafInputStatusType.Exception, "Error occurred processing LeafInput", ex.Message);
|
||||
|
||||
// TODO: Send email
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
|
||||
<add key="TimeZoneId" value="US Eastern Standard Time" />
|
||||
<add key="EmailFromAddress" value="LeafWeb <noreply@leafweb.org>" />
|
||||
<add key="AdminEmailAddresses" value="kolpacksoftware@gmail.com" />
|
||||
<add key="ProcessQueueInterval" value="*/1 * * * *"/>
|
||||
<add key="SmtpHost" value="localhost"/>
|
||||
<add key="SmtpPort" value="25"/>
|
||||
|
||||
Reference in New Issue
Block a user