fix(api): avoid NRE in MailSender on rdv query notifications
The API did not bind the Smtp section and its appsettings lacked Site.Owner, so MailSender threw a NullReferenceException and PostQuery returned 500. Bind Smtp in the API, add Owner/Smtp to the api appsettings template, and log/skip sending when mail configuration is incomplete. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
10d992a07a
commit
0e9f61bd24
5 changed files with 52 additions and 2 deletions
|
|
@ -121,6 +121,22 @@ namespace Yavsc.Org.Tests
|
|||
Assert.Equal(string.Empty, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SendEmailAsync_skips_when_owner_is_not_configured()
|
||||
{
|
||||
var factory = new RejectingSmtpClientFactory();
|
||||
var sender = new MailSender(
|
||||
Options.Create(new SiteSettings { Authority = "example.com" }),
|
||||
Options.Create(new SmtpSettings()),
|
||||
NullLoggerFactory.Instance,
|
||||
new TestStringLocalizer(),
|
||||
factory);
|
||||
|
||||
var result = await sender.SendEmailAsync("Alice", "alice@example.com", "Rdv", "hello");
|
||||
|
||||
Assert.Equal(string.Empty, result);
|
||||
}
|
||||
|
||||
private sealed class RejectingSmtpClientFactory : ISmtpClientFactory
|
||||
{
|
||||
public Yavsc.Interfaces.ISmtpClient CreateClient() => new RejectingSmtpClient();
|
||||
|
|
|
|||
Loading…
Reference in a new issue