using System.Net.Mail; using GamificationService.Exceptions.UtilServices.Email; namespace GamificationService.Utils; public class EmailClient(SmtpClient smtpClient, string emailFrom, ILogger logger) { #region Fields private readonly string _emailFrom = emailFrom; private readonly ILogger _logger = logger; #endregion #region Methods /// /// Sends the email using the SmtpClient instance. /// /// Email to send. /// If the SmtpClient instance fails to send the email. /// Task that represents the asynchronous operation. public async Task SendEmail(MailMessage email, string emailTo) { try { email.To.Add(new MailAddress(emailTo)); await smtpClient.SendMailAsync(email); } catch (Exception ex) { _logger.LogError(ex, ex.Message); throw new SendEmailException("Failed to send email", ex); } } #endregion }