public async Task SendEmailAsync(IList <string> recepients, string subject, string body, CancellationToken cancellationToken = default) { if (!recepients.Any()) { return; } using var smtpClient = BuildSmtpClient(); _logger.LogInfo($"Sending email to:"); foreach (var to in recepients) { try { _logger.LogInfo(to); var mailMessage = GenerateMailMessage(to, subject, body); if (_appSettings.SendEmails) { await smtpClient.SendMailAsync(mailMessage); } else { _logger.LogInfo($"Did not send email to {to} due to config settings"); } } catch (Exception ex) { _logger.LogError($"Failed to send email to: {to}"); _logger.LogError(ex.ToString()); continue; } } _logger.LogInfo("Emails processed!"); }