< Summary

Information
Class: Backend.Services.Impl.BrevoEmailService
Assembly: Backend
File(s): D:\a\smart-meal-planner\smart-meal-planner\backend\Backend\Services\Impl\BrevoEmailService.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 18
Coverable lines: 18
Total lines: 36
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%10%
SendPasswordResetEmailAsync()100%10%

File(s)

D:\a\smart-meal-planner\smart-meal-planner\backend\Backend\Services\Impl\BrevoEmailService.cs

#LineLine coverage
 1using MailKit.Net.Smtp;
 2using MimeKit;
 3
 4namespace Backend.Services.Impl
 5{
 6    public class BrevoEmailService : IEmailService
 7    {
 8        private readonly IConfiguration _config;
 9        private readonly ILogger<BrevoEmailService> _logger;
 10
 011        public BrevoEmailService(IConfiguration config, ILogger<BrevoEmailService> logger)
 12        {
 013            _config = config;
 014            _logger = logger;
 015        }
 16
 17        public async Task SendPasswordResetEmailAsync(string toEmail, string resetLink)
 18        {
 019            var emailMessage = new MimeMessage();
 020            emailMessage.From.Add(new MailboxAddress(
 021                _config["Email:FromName"],
 022                _config["Email:FromEmail"]));
 023            emailMessage.To.Add(MailboxAddress.Parse(toEmail));
 024            emailMessage.Subject = "Reset your password";
 025            emailMessage.Body = new TextPart("html") { Text = $"<p>Click <a href=\"{resetLink}\">here</a> to reset your 
 26
 027            using var client = new SmtpClient();
 028            await client.ConnectAsync("smtp-relay.brevo.com", 587, MailKit.Security.SecureSocketOptions.StartTls);
 029            await client.AuthenticateAsync(_config["Email:SMTPUser"], _config["Email:SMTPPassword"]);
 030            await client.SendAsync(emailMessage);
 031            await client.DisconnectAsync(true);
 32
 033            _logger.LogInformation("Password reset email sent to {Email}", toEmail);
 034        }
 35    }
 36}