chore: configure preprod email secrets
This commit is contained in:
@@ -26,8 +26,14 @@ public static class DependencyInjection
|
||||
|
||||
builder.Services.Configure<EmailerOptions>(
|
||||
builder.Configuration.GetSection(EmailerOptions.ConfigurationSection));
|
||||
builder.Services.AddTransient<IEmailSender, ResendEmailSender>();
|
||||
//builder.Services.AddTransient<IEmailSender, EmailSender>();
|
||||
if (builder.Environment.IsDevelopment())
|
||||
{
|
||||
builder.Services.AddTransient<IEmailSender, LoggerEmailSender>();
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.Services.AddTransient<IEmailSender, ResendEmailSender>();
|
||||
}
|
||||
|
||||
builder.Services.AddHttpClient();
|
||||
|
||||
|
||||
@@ -5,18 +5,15 @@ namespace Socialize.Api.Infrastructure.Emailer.Services;
|
||||
public class LoggerEmailSender(ILogger<IEmailSender> logger)
|
||||
: IEmailSender
|
||||
{
|
||||
public async Task SendEmailAsync(string email, string subject, string message)
|
||||
public Task SendEmailAsync(string email, string subject, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation("Sending email to {Email} with subject: {Subject}", email, subject);
|
||||
await Task.Delay(1000);
|
||||
logger.LogInformation("Email sent successfully to {Email}", email);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to send email to {Email}", email);
|
||||
throw;
|
||||
}
|
||||
logger.LogInformation(
|
||||
"Development email to {Email} with subject {Subject}:{NewLine}{Message}",
|
||||
email,
|
||||
subject,
|
||||
Environment.NewLine,
|
||||
message);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,16 @@ public class ResendEmailSender : IEmailSender
|
||||
_httpClient = httpClientFactory.CreateClient();
|
||||
_options = options.Value;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(_options.ApiKey))
|
||||
{
|
||||
throw new InvalidOperationException("Emailer:ApiKey is required when using Resend email delivery.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(_options.FromEmail))
|
||||
{
|
||||
throw new InvalidOperationException("Emailer:FromEmail is required when using Resend email delivery.");
|
||||
}
|
||||
|
||||
_httpClient.DefaultRequestHeaders.Authorization =
|
||||
new AuthenticationHeaderValue("Bearer", _options.ApiKey);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user