fix #2534 - added Relay Configured site setting to enable sending from users email address
This commit is contained in:
parent
e4ec10ef49
commit
ea463a6548
|
@ -127,7 +127,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="username" HelpText="Enter the username for your SMTP account" ResourceKey="SmptUsername">Username: </Label>
|
||||
<Label Class="col-sm-3" For="username" HelpText="Enter the username for your SMTP account" ResourceKey="SmtpUsername">Username: </Label>
|
||||
<div class="col-sm-9">
|
||||
<input id="username" class="form-control" @bind="@_smtpusername" />
|
||||
</div>
|
||||
|
@ -142,10 +142,19 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="sender" HelpText="Enter the email which emails will be sent from. Please note that this email address may need to be authorized with the SMTP server." ResourceKey="SmptSender">Email Sender: </Label>
|
||||
<Label Class="col-sm-3" For="sender" HelpText="Enter the email which emails will be sent from. Please note that this email address may need to be authorized with the SMTP server." ResourceKey="SmtpSender">Email Sender: </Label>
|
||||
<div class="col-sm-9">
|
||||
<input id="sender" class="form-control" @bind="@_smtpsender" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="relay" HelpText="Only specify this option if you have properly configured an SMTP Relay Service to route your outgoing mail. This option will send notifications from the user's email rather than from the Email Sender specified above." ResourceKey="SmtpRelay">Relay Configured? </Label>
|
||||
<div class="col-sm-9">
|
||||
<select id="relay" class="form-select" @bind="@_smtprelay" required>
|
||||
<option value="True">@SharedLocalizer["Yes"]</option>
|
||||
<option value="False">@SharedLocalizer["No"]</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="retention" HelpText="Number of days of notifications to retain" ResourceKey="Retention">Retention (Days): </Label>
|
||||
|
@ -320,6 +329,7 @@
|
|||
private string _smtppasswordtype = "password";
|
||||
private string _togglesmtppassword = string.Empty;
|
||||
private string _smtpsender = string.Empty;
|
||||
private string _smtprelay = "False";
|
||||
private string _retention = string.Empty;
|
||||
private string _pwaisenabled;
|
||||
private int _pwaappiconfileid = -1;
|
||||
|
@ -393,6 +403,7 @@
|
|||
_smtppassword = SettingService.GetSetting(settings, "SMTPPassword", string.Empty);
|
||||
_togglesmtppassword = SharedLocalizer["ShowPassword"];
|
||||
_smtpsender = SettingService.GetSetting(settings, "SMTPSender", string.Empty);
|
||||
_smtprelay = SettingService.GetSetting(settings, "SMTPRelay", "False");
|
||||
_retention = SettingService.GetSetting(settings, "NotificationRetention", "30");
|
||||
|
||||
if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host))
|
||||
|
@ -532,6 +543,7 @@
|
|||
settings = SettingService.SetSetting(settings, "SMTPUsername", _smtpusername, true);
|
||||
settings = SettingService.SetSetting(settings, "SMTPPassword", _smtppassword, true);
|
||||
settings = SettingService.SetSetting(settings, "SMTPSender", _smtpsender, true);
|
||||
settings = SettingService.SetSetting(settings, "SMTPRelay", _smtprelay, true);
|
||||
settings = SettingService.SetSetting(settings, "NotificationRetention", _retention, true);
|
||||
await SettingService.UpdateSiteSettingsAsync(settings, site.SiteId);
|
||||
|
||||
|
|
|
@ -195,13 +195,13 @@
|
|||
<data name="UseSsl.HelpText" xml:space="preserve">
|
||||
<value>Specify if SSL is required for your SMTP server</value>
|
||||
</data>
|
||||
<data name="SmptUsername.HelpText" xml:space="preserve">
|
||||
<data name="SmtpUsername.HelpText" xml:space="preserve">
|
||||
<value>Enter the username for your SMTP account</value>
|
||||
</data>
|
||||
<data name="SmtpPassword.HelpText" xml:space="preserve">
|
||||
<value>Enter the password for your SMTP account</value>
|
||||
</data>
|
||||
<data name="SmptSender.HelpText" xml:space="preserve">
|
||||
<data name="SmtpSender.HelpText" xml:space="preserve">
|
||||
<value>Enter the email which emails will be sent from. Please note that this email address may need to be authorized with the SMTP server.</value>
|
||||
</data>
|
||||
<data name="EnablePWA.HelpText" xml:space="preserve">
|
||||
|
@ -243,13 +243,13 @@
|
|||
<data name="UseSsl.Text" xml:space="preserve">
|
||||
<value>SSL Enabled: </value>
|
||||
</data>
|
||||
<data name="SmptUsername.Text" xml:space="preserve">
|
||||
<data name="SmtpUsername.Text" xml:space="preserve">
|
||||
<value>Username: </value>
|
||||
</data>
|
||||
<data name="SmtpPassword.Text" xml:space="preserve">
|
||||
<value>Password: </value>
|
||||
</data>
|
||||
<data name="SmptSender.Text" xml:space="preserve">
|
||||
<data name="SmtpSender.Text" xml:space="preserve">
|
||||
<value>Email Sender: </value>
|
||||
</data>
|
||||
<data name="EnablePWA.Text" xml:space="preserve">
|
||||
|
@ -339,4 +339,10 @@
|
|||
<data name="HomePage.Text" xml:space="preserve">
|
||||
<value>Home Page:</value>
|
||||
</data>
|
||||
<data name="SmtpRelay.HelpText" xml:space="preserve">
|
||||
<value>Only specify this option if you have properly configured an SMTP Relay Service to route your outgoing mail. This option will send notifications from the user's email rather than from the Email Sender specified above.</value>
|
||||
</data>
|
||||
<data name="SmtpRelay.Text" xml:space="preserve">
|
||||
<value>Relay Configured?</value>
|
||||
</data>
|
||||
</root>
|
|
@ -66,7 +66,7 @@ namespace Oqtane.Infrastructure
|
|||
List<Notification> notifications = notificationRepository.GetNotifications(site.SiteId, -1, -1).ToList();
|
||||
foreach (Notification notification in notifications)
|
||||
{
|
||||
// get sender and receiver information if not provided
|
||||
// get sender and receiver information from user object if not provided
|
||||
if ((string.IsNullOrEmpty(notification.FromEmail) || string.IsNullOrEmpty(notification.FromDisplayName)) && notification.FromUserId != null)
|
||||
{
|
||||
var user = userRepository.GetUser(notification.FromUserId.Value);
|
||||
|
@ -96,8 +96,42 @@ namespace Oqtane.Infrastructure
|
|||
else
|
||||
{
|
||||
MailMessage mailMessage = new MailMessage();
|
||||
mailMessage.From = new MailAddress(settings["SMTPSender"], site.Name);
|
||||
bool includeheader = true;
|
||||
|
||||
// sender
|
||||
if (settings.ContainsKey("SMTPRelay") && settings["SMTPRelay"] == "True" && !string.IsNullOrEmpty(notification.FromEmail))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(notification.FromDisplayName))
|
||||
{
|
||||
mailMessage.From = new MailAddress(notification.FromEmail, notification.FromDisplayName);
|
||||
}
|
||||
else
|
||||
{
|
||||
mailMessage.From = new MailAddress(notification.FromEmail);
|
||||
}
|
||||
includeheader = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
mailMessage.From = new MailAddress(settings["SMTPSender"], (!string.IsNullOrEmpty(notification.FromDisplayName)) ? notification.FromDisplayName : site.Name);
|
||||
}
|
||||
|
||||
// recipient
|
||||
if (!string.IsNullOrEmpty(notification.ToDisplayName))
|
||||
{
|
||||
mailMessage.To.Add(new MailAddress(notification.ToEmail, notification.ToDisplayName));
|
||||
}
|
||||
else
|
||||
{
|
||||
mailMessage.To.Add(new MailAddress(notification.ToEmail));
|
||||
}
|
||||
|
||||
// subject
|
||||
mailMessage.Subject = notification.Subject;
|
||||
|
||||
//body
|
||||
if (includeheader)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(notification.FromEmail) && !string.IsNullOrEmpty(notification.FromDisplayName))
|
||||
{
|
||||
mailMessage.Body = "From: " + notification.FromDisplayName + "<" + notification.FromEmail + ">" + "\n";
|
||||
|
@ -107,20 +141,18 @@ namespace Oqtane.Infrastructure
|
|||
mailMessage.Body = "From: " + site.Name + "\n";
|
||||
}
|
||||
mailMessage.Body += "Sent: " + notification.CreatedOn + "\n";
|
||||
if (!string.IsNullOrEmpty(notification.ToEmail) && !string.IsNullOrEmpty(notification.ToDisplayName))
|
||||
if (!string.IsNullOrEmpty(notification.ToDisplayName))
|
||||
{
|
||||
mailMessage.To.Add(new MailAddress(notification.ToEmail, notification.ToDisplayName));
|
||||
mailMessage.Body += "To: " + notification.ToDisplayName + "<" + notification.ToEmail + ">" + "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
mailMessage.To.Add(new MailAddress(notification.ToEmail));
|
||||
mailMessage.Body += "To: " + notification.ToEmail + "\n";
|
||||
}
|
||||
mailMessage.Body += "Subject: " + notification.Subject + "\n\n";
|
||||
}
|
||||
mailMessage.Body += notification.Body;
|
||||
|
||||
// set encoding
|
||||
// encoding
|
||||
mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
|
||||
mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user