Skip to content

Commit

Permalink
Store Emails: Fix test email with multiple recipients (#5649)
Browse files Browse the repository at this point in the history
Fixes #5648.
  • Loading branch information
dennisreimann committed Jan 15, 2024
1 parent f7542c9 commit 5935dbf
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions BTCPayServer/Controllers/UIStoresController.Email.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,10 @@ public async Task<IActionResult> StoreEmails(string storeId, StoreEmailRuleViewM
var rule = vm.Rules[i];

if (!string.IsNullOrEmpty(rule.To) && (rule.To.Split(',', StringSplitOptions.RemoveEmptyEntries)
.Any(s => !MailboxAddressValidator.TryParse(s, out var mb))))
.Any(s => !MailboxAddressValidator.TryParse(s, out _))))
{
ModelState.AddModelError($"{nameof(vm.Rules)}[{i}].{nameof(rule.To)}",
"Invalid mailbox address provided. Valid formats are: 'test@example.com' or 'Firstname Lastname <test@example.com>'");

}
else if (!rule.CustomerEmail && string.IsNullOrEmpty(rule.To))
ModelState.AddModelError($"{nameof(vm.Rules)}[{i}].{nameof(rule.To)}",
Expand Down Expand Up @@ -114,8 +113,17 @@ public async Task<IActionResult> StoreEmails(string storeId, StoreEmailRuleViewM
var emailSender = await _emailSenderFactory.GetEmailSender(store.Id);
if (await IsSetupComplete(emailSender))
{
emailSender.SendEmail(MailboxAddress.Parse(rule.To), $"({store.StoreName} test) {rule.Subject}", rule.Body);
message += $"Test email sent to {rule.To} — please verify you received it.";
var recipients = rule.To.Split(",", StringSplitOptions.RemoveEmptyEntries)
.Select(o =>
{
MailboxAddressValidator.TryParse(o, out var mb);
return mb;
})
.Where(o => o != null)
.ToArray();

emailSender.SendEmail(recipients.ToArray(), null, null, $"({store.StoreName} test) {rule.Subject}", rule.Body);
message += "Test email sent — please verify you received it.";
}
else
{
Expand Down

0 comments on commit 5935dbf

Please sign in to comment.