Files
Plushealthtech/plushealthtech/Mail/MailSender.cs
T
Clive e5d1446791
Gitea CI/CD / build (push) Successful in 1m40s
Site pages and AI tasks.
2026-08-20 14:58:52 +10:00

40 lines
1.1 KiB
C#

using System.Net.Mail;
using Microsoft.Extensions.Options;
namespace plushealthtech.Mail
{
/// <summary>
/// Sends outbound email through the configured SMTP server (MailPit in local
/// development). No authentication is used.
/// </summary>
public class MailSender
{
private readonly SmtpOptions _options;
private readonly ILogger<MailSender> _logger;
public MailSender(IOptions<SmtpOptions> options, ILogger<MailSender> logger)
{
_options = options.Value;
_logger = logger;
}
public async Task SendAsync(string subject, string body)
{
using var client = new SmtpClient(_options.Host, _options.Port)
{
EnableSsl = false
};
var message = new MailMessage(_options.From, _options.To)
{
Subject = subject,
Body = body,
IsBodyHtml = false
};
await client.SendMailAsync(message);
_logger.LogInformation("Mail sent to {To} (subject: {Subject})", _options.To, subject);
}
}
}