mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 14:04:26 +01:00
Store Emails (#3611)
* Store Emails * fix test * Update email rules layout * Cleanups * Test cleanups * Add back comments * Update view; add test * Show email rules link even if email settings aren't completed * Validate email addresses * No redirect, display warning * Fix test * Refactoring: Change email argument types to MailAddress * Test fix * Refactoring: Use MailboxAddress * Parse emails properly in controllers and backend Co-authored-by: Dennis Reimann <mail@dennisreimann.de> Co-authored-by: nicolas.dorier <nicolas.dorier@gmail.com>
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Abstractions.Constants;
|
||||
using BTCPayServer.Abstractions.Extensions;
|
||||
@@ -12,6 +11,7 @@ using BTCPayServer.Validation;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MimeKit;
|
||||
|
||||
namespace BTCPayServer.Controllers.GreenField
|
||||
{
|
||||
@@ -39,13 +39,17 @@ namespace BTCPayServer.Controllers.GreenField
|
||||
{
|
||||
return this.CreateAPIError(404, "store-not-found", "The store was not found");
|
||||
}
|
||||
if (!MailboxAddress.TryParse(request.Email, out MailboxAddress to))
|
||||
{
|
||||
ModelState.AddModelError(nameof(request.Email), "Invalid email");
|
||||
return this.CreateValidationError(ModelState);
|
||||
}
|
||||
var emailSender = await _emailSenderFactory.GetEmailSender(storeId);
|
||||
if (emailSender is null )
|
||||
if (emailSender is null)
|
||||
{
|
||||
return this.CreateAPIError(404,"smtp-not-configured", "Store does not have an SMTP server configured.");
|
||||
}
|
||||
|
||||
emailSender.SendEmail(request.Email, request.Subject, request.Body);
|
||||
emailSender.SendEmail(to, request.Subject, request.Body);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user