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:
Andrew Camilleri
2022-06-22 05:05:32 +02:00
committed by GitHub
parent af93cf2adb
commit c2d72e71aa
30 changed files with 429 additions and 120 deletions

View File

@@ -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();
}