| | 1 | | using MailKit.Net.Smtp; |
| | 2 | | using MimeKit; |
| | 3 | |
|
| | 4 | | namespace Backend.Services.Impl |
| | 5 | | { |
| | 6 | | public class BrevoEmailService : IEmailService |
| | 7 | | { |
| | 8 | | private readonly IConfiguration _config; |
| | 9 | | private readonly ILogger<BrevoEmailService> _logger; |
| | 10 | |
|
| 0 | 11 | | public BrevoEmailService(IConfiguration config, ILogger<BrevoEmailService> logger) |
| | 12 | | { |
| 0 | 13 | | _config = config; |
| 0 | 14 | | _logger = logger; |
| 0 | 15 | | } |
| | 16 | |
|
| | 17 | | public async Task SendPasswordResetEmailAsync(string toEmail, string resetLink) |
| | 18 | | { |
| 0 | 19 | | var emailMessage = new MimeMessage(); |
| 0 | 20 | | emailMessage.From.Add(new MailboxAddress( |
| 0 | 21 | | _config["Email:FromName"], |
| 0 | 22 | | _config["Email:FromEmail"])); |
| 0 | 23 | | emailMessage.To.Add(MailboxAddress.Parse(toEmail)); |
| 0 | 24 | | emailMessage.Subject = "Reset your password"; |
| 0 | 25 | | emailMessage.Body = new TextPart("html") { Text = $"<p>Click <a href=\"{resetLink}\">here</a> to reset your |
| | 26 | |
|
| 0 | 27 | | using var client = new SmtpClient(); |
| 0 | 28 | | await client.ConnectAsync("smtp-relay.brevo.com", 587, MailKit.Security.SecureSocketOptions.StartTls); |
| 0 | 29 | | await client.AuthenticateAsync(_config["Email:SMTPUser"], _config["Email:SMTPPassword"]); |
| 0 | 30 | | await client.SendAsync(emailMessage); |
| 0 | 31 | | await client.DisconnectAsync(true); |
| | 32 | |
|
| 0 | 33 | | _logger.LogInformation("Password reset email sent to {Email}", toEmail); |
| 0 | 34 | | } |
| | 35 | | } |
| | 36 | | } |