@@ -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);
diff --git a/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx b/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx
index 4b204eab..e74d0343 100644
--- a/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx
+++ b/Oqtane.Client/Resources/Modules/Admin/Site/Index.resx
@@ -195,13 +195,13 @@
Specify if SSL is required for your SMTP server
-
+
Enter the username for your SMTP account
Enter the password for your SMTP account
-
+
Enter the email which emails will be sent from. Please note that this email address may need to be authorized with the SMTP server.
@@ -243,13 +243,13 @@
SSL Enabled:
-
+
Username:
Password:
-
+
Email Sender:
@@ -339,4 +339,10 @@
Home Page:
+
+ 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.
+
+
+ Relay Configured?
+
\ No newline at end of file
diff --git a/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs b/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs
index 9ad9bbfd..7a184133 100644
--- a/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs
+++ b/Oqtane.Server/Infrastructure/Jobs/NotificationJob.cs
@@ -66,7 +66,7 @@ namespace Oqtane.Infrastructure
List 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,31 +96,63 @@ namespace Oqtane.Infrastructure
else
{
MailMessage mailMessage = new MailMessage();
- mailMessage.From = new MailAddress(settings["SMTPSender"], site.Name);
- mailMessage.Subject = notification.Subject;
- if (!string.IsNullOrEmpty(notification.FromEmail) && !string.IsNullOrEmpty(notification.FromDisplayName))
+ bool includeheader = true;
+
+ // sender
+ if (settings.ContainsKey("SMTPRelay") && settings["SMTPRelay"] == "True" && !string.IsNullOrEmpty(notification.FromEmail))
{
- mailMessage.Body = "From: " + notification.FromDisplayName + "<" + notification.FromEmail + ">" + "\n";
+ if (!string.IsNullOrEmpty(notification.FromDisplayName))
+ {
+ mailMessage.From = new MailAddress(notification.FromEmail, notification.FromDisplayName);
+ }
+ else
+ {
+ mailMessage.From = new MailAddress(notification.FromEmail);
+ }
+ includeheader = false;
}
else
{
- mailMessage.Body = "From: " + site.Name + "\n";
+ mailMessage.From = new MailAddress(settings["SMTPSender"], (!string.IsNullOrEmpty(notification.FromDisplayName)) ? notification.FromDisplayName : site.Name);
}
- mailMessage.Body += "Sent: " + notification.CreatedOn + "\n";
- if (!string.IsNullOrEmpty(notification.ToEmail) && !string.IsNullOrEmpty(notification.ToDisplayName))
+
+ // recipient
+ 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";
+
+ // 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";
+ }
+ else
+ {
+ mailMessage.Body = "From: " + site.Name + "\n";
+ }
+ mailMessage.Body += "Sent: " + notification.CreatedOn + "\n";
+ if (!string.IsNullOrEmpty(notification.ToDisplayName))
+ {
+ mailMessage.Body += "To: " + notification.ToDisplayName + "<" + notification.ToEmail + ">" + "\n";
+ }
+ else
+ {
+ mailMessage.Body += "To: " + notification.ToEmail + "\n";
+ }
+ }
mailMessage.Body += notification.Body;
- // set encoding
+ // encoding
mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
mailMessage.BodyEncoding = System.Text.Encoding.UTF8;