feature: add reply-to address for email service

This commit is contained in:
Gary Sharp
2021-02-05 15:24:20 +11:00
parent f7fdfb0c8a
commit e11d0871c4
7 changed files with 112 additions and 34 deletions
+1
View File
@@ -5,6 +5,7 @@ namespace Disco.Models.Services.Messaging
public class Email
{
public string From { get; set; }
public string ReplyTo { get; set; }
public List<string> To { get; } = new List<string>();
public List<string> CC { get; } = new List<string>();
public List<string> BCC { get; } = new List<string>();
+11 -1
View File
@@ -15,6 +15,7 @@ namespace Disco.Services.Messaging
private static bool smtpEnableSsl;
private static string smtpUsername;
private static string smtpPassword;
private static string smtpReplyToAddress;
public static bool IsConfigured { get; private set; }
@@ -26,7 +27,7 @@ namespace Disco.Services.Messaging
}
}
public static void ValidateConfiguration(string smtpServer, int smtpPort, string fromAddress, bool enableSsl, string username, string password)
public static void ValidateConfiguration(string smtpServer, int smtpPort, string fromAddress, string replyToAddress, bool enableSsl, string username, string password)
{
// if smtpServer is null, we aren't configured (emailing is disabled)
if (!string.IsNullOrWhiteSpace(smtpServer))
@@ -38,6 +39,9 @@ namespace Disco.Services.Messaging
throw new ArgumentOutOfRangeException(nameof(fromAddress), "From Address is required");
// try parse FromAddress
new MailAddress(fromAddress);
// try parse reply-to address
if (!string.IsNullOrWhiteSpace(replyToAddress))
new MailAddress(replyToAddress);
}
}
@@ -49,6 +53,7 @@ namespace Disco.Services.Messaging
smtpFromAddress = systemConfiguration.EmailFromAddress;
smtpUsername = systemConfiguration.EmailUsername;
smtpPassword = systemConfiguration.EmailPassword;
smtpReplyToAddress = systemConfiguration.EmailReplyToAddress;
IsConfigured =
!string.IsNullOrWhiteSpace(smtpServer) &&
@@ -73,6 +78,11 @@ namespace Disco.Services.Messaging
else
message.From = new MailAddress(smtpFromAddress);
if (!string.IsNullOrWhiteSpace(email.ReplyTo))
message.ReplyToList.Add(new MailAddress(email.ReplyTo));
else if (!string.IsNullOrWhiteSpace(smtpReplyToAddress))
message.ReplyToList.Add(new MailAddress(smtpReplyToAddress));
if (email.To.Count > 0)
{
foreach (var recipient in email.To)
@@ -368,18 +368,19 @@ namespace Disco.Web.Areas.API.Controllers
#region Email Settings
[DiscoAuthorize(Claims.Config.System.ConfigureEmail), ValidateInput(false), ValidateAntiForgeryToken]
public virtual ActionResult UpdateEmailSettings(string SmtpServer, int? SmtpPort, string FromAddress, bool EnableSsl, string Username, string Password, bool redirect = false)
public virtual ActionResult UpdateEmailSettings(string SmtpServer, int? SmtpPort, string FromAddress, string ReplyToAddress, bool EnableSsl, string Username, string Password, bool redirect = false)
{
// Default Port
if (!SmtpPort.HasValue)
SmtpPort = 25;
EmailService.ValidateConfiguration(SmtpServer, SmtpPort.Value, FromAddress, EnableSsl, Username, Password);
EmailService.ValidateConfiguration(SmtpServer, SmtpPort.Value, FromAddress, ReplyToAddress, EnableSsl, Username, Password);
SystemConfiguration config = Database.DiscoConfiguration;
config.EmailSmtpServer = SmtpServer;
config.EmailSmtpPort = SmtpPort.Value;
config.EmailFromAddress = FromAddress;
config.EmailReplyToAddress = ReplyToAddress;
config.EmailEnableSsl = EnableSsl;
config.EmailUsername = Username;
config.EmailPassword = Password;
@@ -103,6 +103,7 @@ namespace Disco.Web.Areas.Config.Models.SystemConfig
public string EmailSmtpServer { get; set; }
public int EmailSmtpPort { get; set; }
public string EmailFromAddress { get; set; }
public string EmailReplyToAddress { get; set; }
[Display(Name = "Enable SSL")]
public bool EmailEnableSsl { get; set; }
public string EmailUsername { get; set; }
@@ -130,6 +131,7 @@ namespace Disco.Web.Areas.Config.Models.SystemConfig
EmailSmtpServer = config.EmailSmtpServer,
EmailSmtpPort = config.EmailSmtpPort,
EmailFromAddress = config.EmailFromAddress,
EmailReplyToAddress = config.EmailReplyToAddress,
EmailEnableSsl = config.EmailEnableSsl,
EmailUsername = config.EmailUsername,
EmailPassword = config.EmailPassword,
@@ -696,6 +696,15 @@ else
@Html.ValidationMessageFor(m => m.EmailFromAddress)
</td>
</tr>
<tr>
<th style="width: 135px">
Reply To Address:
</th>
<td>
@Html.EditorFor(m => m.EmailReplyToAddress)<br />
@Html.ValidationMessageFor(m => m.EmailReplyToAddress)
</td>
</tr>
<tr>
<th style="width: 135px">
&nbsp;
@@ -848,6 +857,14 @@ else
@Html.DisplayFor(m => m.EmailFromAddress)
</td>
</tr>
<tr>
<th style="width: 135px">
Reply To Address:
</th>
<td>
@Html.DisplayFor(m => m.EmailReplyToAddress)
</td>
</tr>
<tr>
<th style="width: 135px">
Enable SSL:
@@ -1982,12 +1982,40 @@ WriteLiteral("\r\n </td>\r\n </tr>\r\n <tr>
WriteLiteral(" style=\"width: 135px\"");
WriteLiteral(">\r\n &nbsp;\r\n </th>\r\n <td>\r\n");
WriteLiteral(">\r\n Reply To Address:\r\n </th>\r\n " +
"<td>\r\n");
WriteLiteral(" ");
#line 704 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.EditorFor(m => m.EmailReplyToAddress));
#line default
#line hidden
WriteLiteral("<br />\r\n");
WriteLiteral(" ");
#line 705 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.ValidationMessageFor(m => m.EmailReplyToAddress));
#line default
#line hidden
WriteLiteral("\r\n </td>\r\n </tr>\r\n <tr>\r\n <th" +
"");
WriteLiteral(" style=\"width: 135px\"");
WriteLiteral(">\r\n &nbsp;\r\n </th>\r\n <td>\r\n");
WriteLiteral(" ");
#line 713 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.CheckBoxFor(m => m.EmailEnableSsl));
@@ -1996,7 +2024,7 @@ WriteLiteral(" ");
WriteLiteral(" ");
#line 704 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 713 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.LabelFor(m => m.EmailEnableSsl));
@@ -2012,7 +2040,7 @@ WriteLiteral(">\r\n Username:\r\n </th>\r\n
WriteLiteral(" ");
#line 712 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 721 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.EditorFor(m => m.EmailUsername));
@@ -2023,7 +2051,7 @@ WriteLiteral("<br />\r\n");
WriteLiteral(" ");
#line 713 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 722 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.ValidationMessageFor(m => m.EmailUsername));
@@ -2039,7 +2067,7 @@ WriteLiteral(">\r\n Password:\r\n </th>\r\n
WriteLiteral(" ");
#line 721 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 730 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.EditorFor(m => m.EmailPassword));
@@ -2050,7 +2078,7 @@ WriteLiteral("<br />\r\n");
WriteLiteral(" ");
#line 722 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 731 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.ValidationMessageFor(m => m.EmailPassword));
@@ -2066,7 +2094,7 @@ WriteLiteral(">\r\n &nbsp;\r\n </th>\r\n
WriteLiteral(" ");
#line 730 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 739 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.AntiForgeryToken());
@@ -2083,7 +2111,7 @@ WriteLiteral(" class=\"button small\"");
WriteLiteral(" ");
#line 731 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 740 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Model.EmailIsConfigured ? null : "disabled");
@@ -2100,7 +2128,7 @@ WriteLiteral(" class=\"button small\"");
WriteLiteral(">Save Email Settings</button>");
#line 732 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 741 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(AjaxHelpers.AjaxLoader());
@@ -2121,13 +2149,13 @@ WriteLiteral(" class=\"fa fa-envelope information\"");
WriteLiteral("></i>&nbsp;Recipient Email Address:</h4>\r\n <br />\r\n");
#line 736 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 745 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line default
#line hidden
#line 736 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 745 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
using (Html.BeginForm(MVC.API.System.SendTestEmail(), FormMethod.Post))
{
@@ -2152,33 +2180,33 @@ WriteLiteral(" name=\"Recipient\"");
WriteLiteral(" type=\"text\"");
WriteAttribute("value", Tuple.Create(" value=\"", 34321), Tuple.Create("\"", 34354)
WriteAttribute("value", Tuple.Create(" value=\"", 34655), Tuple.Create("\"", 34688)
#line 739 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
, Tuple.Create(Tuple.Create("", 34329), Tuple.Create<System.Object, System.Int32>(CurrentUser.EmailAddress
#line 748 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
, Tuple.Create(Tuple.Create("", 34663), Tuple.Create<System.Object, System.Int32>(CurrentUser.EmailAddress
#line default
#line hidden
, 34329), false)
, 34663), false)
);
WriteLiteral(" />\r\n");
#line 740 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 749 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line default
#line hidden
#line 740 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 749 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.AntiForgeryToken());
#line default
#line hidden
#line 740 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 749 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
}
@@ -2196,7 +2224,7 @@ WriteLiteral(@" </div>
var url = '");
#line 750 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 759 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Url.Action(MVC.API.System.UpdateEmailSettings()));
@@ -2258,7 +2286,7 @@ WriteLiteral("\';\r\n var data = {\r\n
" </tr>\r\n </table>\r\n </div>\r\n");
#line 821 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 830 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
}
else
{
@@ -2283,7 +2311,7 @@ WriteLiteral(">\r\n SMTP Server:\r\n </th>\r\n
WriteLiteral(" ");
#line 832 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 841 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.DisplayFor(m => m.EmailSmtpServer));
@@ -2299,7 +2327,7 @@ WriteLiteral(">\r\n Port:\r\n </th>\r\n
WriteLiteral(" ");
#line 840 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 849 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.DisplayFor(m => m.EmailSmtpPort));
@@ -2316,7 +2344,7 @@ WriteLiteral(">\r\n Default From Address:\r\n
WriteLiteral(" ");
#line 848 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 857 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.DisplayFor(m => m.EmailFromAddress));
@@ -2327,13 +2355,30 @@ WriteLiteral("\r\n </td>\r\n </tr>\r\n <tr>
WriteLiteral(" style=\"width: 135px\"");
WriteLiteral(">\r\n Reply To Address:\r\n </th>\r\n " +
"<td>\r\n");
WriteLiteral(" ");
#line 865 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.DisplayFor(m => m.EmailReplyToAddress));
#line default
#line hidden
WriteLiteral("\r\n </td>\r\n </tr>\r\n <tr>\r\n <th" +
"");
WriteLiteral(" style=\"width: 135px\"");
WriteLiteral(">\r\n Enable SSL:\r\n </th>\r\n <td>\r\n" +
"");
WriteLiteral(" ");
#line 856 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 873 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.CheckBoxFor(m => m.EmailEnableSsl, new { disabled = "disabled" }));
@@ -2342,7 +2387,7 @@ WriteLiteral(" ");
WriteLiteral(" ");
#line 856 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 873 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.LabelFor(m => m.EmailEnableSsl));
@@ -2358,7 +2403,7 @@ WriteLiteral(">\r\n Username:\r\n </th>\r\n
WriteLiteral(" ");
#line 864 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 881 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.DisplayFor(m => m.EmailUsername));
@@ -2374,7 +2419,7 @@ WriteLiteral(">\r\n Password:\r\n </th>\r\n
"table>\r\n </div>\r\n");
#line 877 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 894 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
}
@@ -2389,7 +2434,7 @@ WriteLiteral(">\r\n");
WriteLiteral(" ");
#line 879 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 896 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.ActionLinkButton("Update Device Last Network Logons", MVC.API.System.UpdateLastNetworkLogonDates()));
@@ -335,6 +335,7 @@ namespace Disco.Web.Areas.API.Controllers
public readonly string SmtpServer = "SmtpServer";
public readonly string SmtpPort = "SmtpPort";
public readonly string FromAddress = "FromAddress";
public readonly string ReplyToAddress = "ReplyToAddress";
public readonly string EnableSsl = "EnableSsl";
public readonly string Username = "Username";
public readonly string Password = "Password";
@@ -608,20 +609,21 @@ namespace Disco.Web.Areas.API.Controllers
}
[NonAction]
partial void UpdateEmailSettingsOverride(T4MVC_System_Web_Mvc_ActionResult callInfo, string SmtpServer, int? SmtpPort, string FromAddress, bool EnableSsl, string Username, string Password, bool redirect);
partial void UpdateEmailSettingsOverride(T4MVC_System_Web_Mvc_ActionResult callInfo, string SmtpServer, int? SmtpPort, string FromAddress, string ReplyToAddress, bool EnableSsl, string Username, string Password, bool redirect);
[NonAction]
public override System.Web.Mvc.ActionResult UpdateEmailSettings(string SmtpServer, int? SmtpPort, string FromAddress, bool EnableSsl, string Username, string Password, bool redirect)
public override System.Web.Mvc.ActionResult UpdateEmailSettings(string SmtpServer, int? SmtpPort, string FromAddress, string ReplyToAddress, bool EnableSsl, string Username, string Password, bool redirect)
{
var callInfo = new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.UpdateEmailSettings);
ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "SmtpServer", SmtpServer);
ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "SmtpPort", SmtpPort);
ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "FromAddress", FromAddress);
ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "ReplyToAddress", ReplyToAddress);
ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "EnableSsl", EnableSsl);
ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "Username", Username);
ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "Password", Password);
ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "redirect", redirect);
UpdateEmailSettingsOverride(callInfo, SmtpServer, SmtpPort, FromAddress, EnableSsl, Username, Password, redirect);
UpdateEmailSettingsOverride(callInfo, SmtpServer, SmtpPort, FromAddress, ReplyToAddress, EnableSsl, Username, Password, redirect);
return callInfo;
}