Refactor email account configuration for multi-account support
Refactored `EmailAccountDto` to represent a single account with immutable properties and added an `Id` field. Introduced `EmailAccountsOptions` to manage multiple accounts and bound it to the `EmailAccounts` configuration section. Updated `DependencyInjection` to register `EmailAccountsOptions` and removed the old single-account binding. Refactored `LimilabsEmailService` to use `EmailAccountsOptions` and select the appropriate account dynamically. Replaced the `EmailAccount` section in `appsettings.Secrets.json` with a new `EmailAccounts` section supporting multiple accounts. Added a package reference for `Microsoft.Extensions.Options. ConfigurationExtensions` to support the options pattern.
This commit is contained in:
@@ -1,21 +1,27 @@
|
||||
namespace DigitalData.MessagingService.Application.Common.Dtos;
|
||||
|
||||
/// <summary>
|
||||
/// DTO for EmailAccount query results.
|
||||
/// DTO for a single email account configuration.
|
||||
/// </summary>
|
||||
public class EmailAccountDto
|
||||
{
|
||||
public string Username { get; set; } = null!;
|
||||
/// <summary>
|
||||
/// Logical name to identify this account (e.g. "default", "support").
|
||||
/// </summary>
|
||||
public int Id { get; init; }
|
||||
|
||||
public string Password { get; set; } = null!;
|
||||
public required string Username { get; init; }
|
||||
|
||||
public bool PasswordEncrypted { get; set; } = false;
|
||||
public required string Password { get; init; }
|
||||
|
||||
public string SmtpServer { get; set; } = null!;
|
||||
public bool PasswordEncrypted { get; init; } = false;
|
||||
|
||||
public int SmtpPort { get; set; }
|
||||
public required string SmtpServer { get; init; }
|
||||
|
||||
public bool SmtpUseSsl { get; set; }
|
||||
public int SmtpPort { get; init; }
|
||||
|
||||
public bool UseOAuth2 { get; set; }
|
||||
public bool SmtpUseSsl { get; init; }
|
||||
|
||||
public bool UseOAuth2 { get; init; }
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using DigitalData.MessagingService.Application.Common.Dtos;
|
||||
|
||||
namespace DigitalData.MessagingService.Application.Common.Options;
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper options class that holds a list of <see cref="EmailAccountDto"/> entries
|
||||
/// bound from the <c>EmailAccounts</c> configuration section.
|
||||
/// </summary>
|
||||
public class EmailAccountsOptions
|
||||
{
|
||||
public const string SectionName = "EmailAccounts";
|
||||
|
||||
/// <summary>
|
||||
/// The list of configured email accounts.
|
||||
/// </summary>
|
||||
public required IEnumerable<EmailAccountDto> Accounts { get; init; } = [];
|
||||
}
|
||||
Reference in New Issue
Block a user