Contact: ontvangstadres uit de site-instellingen (instelling > env), PUT /contact-settings/recipient en Berichten-veld (CMS-U11)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,25 +18,27 @@ public sealed class ContactMailSender(
|
||||
IMailTemplateRenderer renderer,
|
||||
ILanguageResolver languages,
|
||||
ISiteSettingsService siteSettings,
|
||||
IContactSettingsService contactSettings,
|
||||
IMailAvailability availability,
|
||||
IOptions<EmailOptions> email,
|
||||
IOptions<AppMailOptions> app,
|
||||
IOptions<ContactOptions> contact,
|
||||
ILogger<ContactMailSender> logger) : IContactMailSender
|
||||
{
|
||||
public string? NotReadyReason()
|
||||
public async Task<string?> NotReadyReasonAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (!availability.IsEnabled)
|
||||
{
|
||||
return ContactMailResult.Disabled;
|
||||
}
|
||||
|
||||
return EmailAddressRules.IsValidAddress(contact.Value.RecipientEmail) ? null : ContactMailResult.RecipientNotConfigured;
|
||||
var (address, _) = await contactSettings.GetEffectiveRecipientAsync(cancellationToken);
|
||||
return address is null ? ContactMailResult.RecipientNotConfigured : null;
|
||||
}
|
||||
|
||||
public async Task<ContactMailResult> SendAsync(ContactMessage message, CancellationToken cancellationToken)
|
||||
{
|
||||
var notReady = NotReadyReason();
|
||||
var notReady = await NotReadyReasonAsync(cancellationToken);
|
||||
if (notReady is not null)
|
||||
{
|
||||
return new ContactMailResult(ContactMailOutcome.Skipped, notReady);
|
||||
@@ -44,6 +46,8 @@ public sealed class ContactMailSender(
|
||||
|
||||
try
|
||||
{
|
||||
// Read per send: the administrator's setting wins over the environment and changes without a restart.
|
||||
var (recipient, _) = await contactSettings.GetEffectiveRecipientAsync(cancellationToken);
|
||||
var (fromAddress, fromName) = await siteSettings.GetEffectiveSenderAsync(cancellationToken);
|
||||
var baseUrl = app.Value.PublicBaseUrl.TrimEnd('/');
|
||||
var language = languages.Resolve(null);
|
||||
@@ -65,7 +69,7 @@ public sealed class ContactMailSender(
|
||||
var rendered = renderer.Render(MailKind.ContactMessage, language, model);
|
||||
var result = await sender.SendAsync(
|
||||
new OutgoingMail(
|
||||
contact.Value.RecipientEmail!.Trim(), rendered.Subject, rendered.Html, rendered.Text,
|
||||
recipient!, rendered.Subject, rendered.Html, rendered.Text,
|
||||
fromAddress, fromName,
|
||||
ReplyToAddress: message.Email,
|
||||
ReplyToName: EmailAddressRules.IsValidDisplayName(message.Name) ? message.Name : null),
|
||||
|
||||
Reference in New Issue
Block a user