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:
Paul Schneider 2026-10-21 12:20:38 +01:00
commit 0e9f61bd24
Signed by: notazof
GPG key ID: AD4B9B545FBD7D12
5 changed files with 52 additions and 2 deletions

View file

@ -104,6 +104,12 @@ namespace Yavsc.Services
try
{
logger.LogInformation($"SendEmail for {email} : {subject}");
if (string.IsNullOrWhiteSpace(siteSettings?.Owner?.EMail)
|| string.IsNullOrWhiteSpace(smtpSettings?.Host))
{
logger.LogError("Email not sent: mail configuration is incomplete (Site:Owner:EMail and Smtp:Host are required). To={To}, Subject={Subject}", email, subject);
return string.Empty;
}
MimeMessage msg = new();
msg.From.Add(BuildMailboxAddress(siteSettings.Owner.Name, siteSettings.Owner.EMail));
msg.To.Add(BuildMailboxAddress(name, email));
@ -139,7 +145,7 @@ namespace Yavsc.Services
}
catch (FormatException ex)
{
logger.LogError(ex, "Refusing to send email because the recipient or sender address is malformed. To={To}, From={From}", email, siteSettings.Owner.EMail);
logger.LogError(ex, "Refusing to send email because the recipient or sender address is malformed. To={To}, From={From}", email, siteSettings?.Owner?.EMail);
logger.LogError(ex.Message);
if (ex.InnerException!=null)
logger.LogError(ex.InnerException.Message);