Update email configuration
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Mail;
|
||||
using LeafWeb.Core.DAL;
|
||||
using LeafWeb.Core.Entities;
|
||||
using LeafWeb.Core.Utility;
|
||||
using NLog;
|
||||
|
||||
namespace LeafWeb.Web.Services
|
||||
@@ -23,7 +25,15 @@ namespace LeafWeb.Web.Services
|
||||
{
|
||||
_dataService = dataService;
|
||||
|
||||
_smtpClient = new SmtpClient();
|
||||
_smtpClient = new SmtpClient(
|
||||
ConfigurationManager.AppSettings["SmtpHost"],
|
||||
Convert.ToInt32(ConfigurationManager.AppSettings["SmtpPort"]));
|
||||
|
||||
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["SmtpUserName"]))
|
||||
_smtpClient.Credentials = new NetworkCredential(
|
||||
ConfigurationManager.AppSettings["SmtpUserName"],
|
||||
ConfigurationManager.AppSettings["SmtpPassword"]
|
||||
);
|
||||
|
||||
_emaialFromAddress = ConfigurationManager.AppSettings["EmailFromAddress"];
|
||||
}
|
||||
@@ -31,26 +41,32 @@ namespace LeafWeb.Web.Services
|
||||
public EmailNotificationService() : this(new DataService())
|
||||
{ }
|
||||
|
||||
public void SendLeafWebError(int leafInputId, string errorMessage)
|
||||
{
|
||||
var leafInput = _dataService.GetLeafInput(leafInputId);
|
||||
var body = $"Your leaf analysis job, {leafInput.Identifier}, encountered the following errors." + Environment.NewLine
|
||||
+ "You will need to correct your input and resubmit." + Environment.NewLine + Environment.NewLine
|
||||
+ errorMessage;
|
||||
var message = new MailMessage(_emaialFromAddress, leafInput.Email, "LeafWeb processing error", body);
|
||||
SendMessage(message);
|
||||
}
|
||||
|
||||
public void SendLeafWebComplete(int leafInputId)
|
||||
{
|
||||
var leafInput = _dataService.GetLeafInput(leafInputId);
|
||||
var body = $"Your leaf analysis job, {leafInput.Identifier}, has completed." + Environment.NewLine;
|
||||
var message = new MailMessage(_emaialFromAddress, leafInput.Email, "LeafWeb results", body);
|
||||
|
||||
var outputErrorMessage = leafInput.OutputErrorMessage;
|
||||
if (outputErrorMessage != null)
|
||||
SendLeafWebError(leafInput, outputErrorMessage.Contents.GetString());
|
||||
else
|
||||
SendLeafWebSuccess(leafInput);
|
||||
}
|
||||
|
||||
private void SendLeafWebSuccess(LeafInput leafInput)
|
||||
{
|
||||
var fileStreams =
|
||||
(from outputFile in
|
||||
leafInput.OutputFiles
|
||||
select Tuple.Create(outputFile, new MemoryStream(outputFile.Contents))).ToList();
|
||||
select Tuple.Create(outputFile, new MemoryStream(outputFile.Contents))).ToList();
|
||||
|
||||
var body = $"Your leaf analysis job, {leafInput.Identifier}, has completed." + Environment.NewLine;
|
||||
if (leafInput.OutputWarningMessage != null)
|
||||
body += "The following warning message was generated."
|
||||
+ Environment.NewLine + Environment.NewLine
|
||||
+ leafInput.OutputWarningMessage.Contents.GetString()
|
||||
+ Environment.NewLine;
|
||||
body += "Please see the attached results.";
|
||||
var message = new MailMessage(_emaialFromAddress, leafInput.Email, "LeafWeb results", body);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -72,6 +88,17 @@ namespace LeafWeb.Web.Services
|
||||
}
|
||||
}
|
||||
|
||||
private void SendLeafWebError(LeafInput leafInput, string errorMessage)
|
||||
{
|
||||
var body = $"Your leaf analysis job, {leafInput.Identifier}, encountered the following errors." + Environment.NewLine
|
||||
+ Environment.NewLine + Environment.NewLine
|
||||
+ errorMessage
|
||||
+ Environment.NewLine + Environment.NewLine
|
||||
+ "You will need to correct your input and resubmit.";
|
||||
var message = new MailMessage(_emaialFromAddress, leafInput.Email, "LeafWeb processing error", body);
|
||||
SendMessage(message);
|
||||
}
|
||||
|
||||
private void SendMessage(MailMessage mailMessage)
|
||||
{
|
||||
try
|
||||
|
||||
+4
-7
@@ -24,14 +24,11 @@
|
||||
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
|
||||
<add key="TimeZoneId" value="US Eastern Standard Time" />
|
||||
<add key="EmailFromAddress" value="LeafWeb <noreply@leafweb.org>" />
|
||||
<add key="SmtpHost" value="localhost"/>
|
||||
<add key="SmtpPort" value="25"/>
|
||||
<add key="SmtpUserName" value=""/>
|
||||
<add key="SmtpPassword" value=""/>
|
||||
</appSettings>
|
||||
<system.net>
|
||||
<mailSettings>
|
||||
<smtp deliveryMethod="Network" from="LeafWeb <noreply@leafweb.org>">
|
||||
<network host="localhost" />
|
||||
</smtp>
|
||||
</mailSettings>
|
||||
</system.net>
|
||||
<system.web>
|
||||
<compilation debug="true" targetFramework="4.5" />
|
||||
<!-- max 1GB -->
|
||||
|
||||
Reference in New Issue
Block a user