Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public class SmtpSettingsDto
/// </summary>
public bool SupportSmtpRelay { get; set; }

/// <summary>
/// If true, the from address on all outgoing emails will always be overridden with the address configured in settings, ignoring any caller-supplied from address.
/// </summary>
public bool ForceFromAddressFromSettings { get; set; }

/// <summary>
/// If not null or empty the all outgoing emails will be sent to this email address, is used for testing
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ await _emailSettings.EmailSettings.SetValueAsync(new EmailSettings
RedirectAllMessagesTo = input.RedirectAllMessagesTo,
});

await _emailSettings.SmtpSettings.SetValueAsync(new SmtpSettings {
await _emailSettings.SmtpSettings.SetValueAsync(new SmtpSettings {
Host = input.Host,
Port = input.Port,
Domain = input.Domain,
Expand All @@ -49,6 +49,7 @@ await _emailSettings.SmtpSettings.SetValueAsync(new SmtpSettings {
EnableSsl = input.EnableSsl,
DefaultFromAddress = input.DefaultFromAddress,
DefaultFromDisplayName = input.DefaultFromDisplayName,
ForceFromAddressFromSettings = input.ForceFromAddressFromSettings,
});

return true;
Expand All @@ -73,6 +74,7 @@ public async Task<SmtpSettingsDto> GetSmtpSettingsAsync()
DefaultFromAddress = smtpSettings.DefaultFromAddress,
DefaultFromDisplayName = smtpSettings.DefaultFromDisplayName,
SupportSmtpRelay = smtpSettings.UseSmtpRelay,
ForceFromAddressFromSettings = smtpSettings.ForceFromAddressFromSettings,

RedirectAllMessagesTo = emailSettings.RedirectAllMessagesTo,
EmailsEnabled = emailSettings.EmailsEnabled,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Abp.UI;
using Castle.Core.Logging;
using Castle.Core.Logging;
using Shesha.Configuration;
using Shesha.Configuration.Email;
using Shesha.Domain;
Expand All @@ -11,6 +10,7 @@
using System.Collections.Generic;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;

namespace Shesha.Notifications
Expand Down Expand Up @@ -140,14 +140,24 @@ private MailMessage BuildMessageWith(string? fromAddress, string toAddress, stri
IsBodyHtml = true,
};

if (string.IsNullOrWhiteSpace(fromAddress))
if (string.IsNullOrWhiteSpace(fromAddress) || smtpSettings.ForceFromAddressFromSettings)
{
if (!StringHelper.IsValidEmail(smtpSettings.DefaultFromAddress))
if (smtpSettings.UseSmtpRelay && !string.IsNullOrWhiteSpace(smtpSettings.DefaultFromAddress))
{
throw new UserFriendlyException("Default from address is not valid!");
message.From = new MailAddress(
smtpSettings.DefaultFromAddress,
smtpSettings.DefaultFromDisplayName,
Encoding.UTF8
);
}
else
{
message.From = new MailAddress(
smtpSettings.UserName,
null,
Encoding.UTF8
);
}

message.From = new MailAddress(smtpSettings.DefaultFromAddress);
}
Comment thread
MarshallRJ marked this conversation as resolved.
else if (StringHelper.IsValidEmail(fromAddress))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,10 @@ public class SmtpSettings
/// If true, indicate that SMTP relay service will be used where it's needed (e.g. if the application needs to notify one person about the action that was performed by another person then real person's email address will be used for the 'from' address, otherwise 'Site Email' will be used)
/// </summary>
public bool UseSmtpRelay { get; set; }

/// <summary>
/// If true, the from address on all outgoing emails will always be overridden with the address configured in settings, ignoring any caller-supplied from address.
/// </summary>
public bool ForceFromAddressFromSettings { get; set; }
}
}