Add notification inbox and restrict email logging
This commit is contained in:
1 parent
33b6864d3b
commit
9ca23a2c15
5 files changed
+114
-3
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using Helpdesk.Application.Abstractions;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Helpdesk.Infrastructure.Email;
|
||||
@@ -7,14 +8,20 @@ namespace Helpdesk.Infrastructure.Email;
|
||||
/// Vývojová náhrada odesílání e-mailů – obsah zapíše do logu (odkaz pro ověření e-mailu je tak vidět
|
||||
/// v <c>docker compose logs api</c>). Odesílání přes SMTP (MailKit + Mailpit) přijde s notifikacemi.
|
||||
/// </summary>
|
||||
internal sealed partial class LoggingEmailSender(ILogger<LoggingEmailSender> logger) : IEmailSender
|
||||
internal sealed partial class LoggingEmailSender(ILogger<LoggingEmailSender> logger, IHostEnvironment environment) : IEmailSender
|
||||
{
|
||||
public Task SendAsync(string to, string subject, string body, CancellationToken cancellationToken = default)
|
||||
{
|
||||
LogEmail(to, subject, body);
|
||||
if (environment.IsDevelopment())
|
||||
LogEmail(to, subject, body);
|
||||
else
|
||||
LogMissingTransport();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
[LoggerMessage(Level = LogLevel.Information, Message = "E-mail pro {To} – {Subject}:\n{Body}")]
|
||||
private partial void LogEmail(string to, string subject, string body);
|
||||
|
||||
[LoggerMessage(Level = LogLevel.Warning, Message = "E-mail nebyl odeslán. Pro toto prostředí není nakonfigurován poštovní transport.")]
|
||||
private partial void LogMissingTransport();
|
||||
}
|
||||
Reference in new issue
Block a user