mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
fix(email): ensure all email settings are validated before sending; allow nullable From property
This commit is contained in:
@@ -16,7 +16,12 @@ namespace SharpbinV3.Server.Services
|
|||||||
|
|
||||||
public async Task SendAsync(string to, string subject, string body)
|
public async Task SendAsync(string to, string subject, string body)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(settings.Host) || string.IsNullOrWhiteSpace(settings.User) || string.IsNullOrWhiteSpace(settings.Password))
|
if (
|
||||||
|
string.IsNullOrWhiteSpace(settings.Host)
|
||||||
|
|| string.IsNullOrWhiteSpace(settings.User)
|
||||||
|
|| string.IsNullOrWhiteSpace(settings.Password)
|
||||||
|
|| string.IsNullOrWhiteSpace(settings.From)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
logger.LogWarning($"Email settings are not fully configured. Skipping sending email to {to}");
|
logger.LogWarning($"Email settings are not fully configured. Skipping sending email to {to}");
|
||||||
return;
|
return;
|
||||||
@@ -51,7 +56,7 @@ namespace SharpbinV3.Server.Services
|
|||||||
private async Task SendNowAsync(QueuedEmail email, CancellationToken cancellationToken)
|
private async Task SendNowAsync(QueuedEmail email, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var message = new MimeMessage();
|
var message = new MimeMessage();
|
||||||
message.From.Add(new MailboxAddress("Sharpbin", settings.From));
|
message.From.Add(new MailboxAddress("Sharpbin", settings.From!));
|
||||||
message.To.Add(MailboxAddress.Parse(email.To));
|
message.To.Add(MailboxAddress.Parse(email.To));
|
||||||
message.Subject = email.Subject;
|
message.Subject = email.Subject;
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace SharpbinV3.Server.Settings
|
|||||||
public string Password { get; set; } = string.Empty;
|
public string Password { get; set; } = string.Empty;
|
||||||
|
|
||||||
[EmailAddress]
|
[EmailAddress]
|
||||||
public string From { get; set; } = string.Empty;
|
public string? From { get; set; }
|
||||||
public string Verification_HMAC_Secret { get; set; } = string.Empty;
|
public string Verification_HMAC_Secret { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user