diff --git a/FabApprovalWorkerService/Services/SmtpService.cs b/FabApprovalWorkerService/Services/SmtpService.cs index 04b0d38..6dac67c 100644 --- a/FabApprovalWorkerService/Services/SmtpService.cs +++ b/FabApprovalWorkerService/Services/SmtpService.cs @@ -13,15 +13,15 @@ public interface ISmtpService { public class SmtpService : ISmtpService { private ILogger _logger; private ISmtpClientWrapper _smtpClient; - private string _environmentName; + private bool _shouldSendEmail; public SmtpService(ILogger logger, ISmtpClientWrapper smtpClient) { _logger = logger ?? throw new ArgumentNullException("ILogger not injected"); _smtpClient = smtpClient ?? throw new ArgumentNullException("SmtpClient not injected"); - _environmentName = Environment.GetEnvironmentVariable("FabApprovalEnvironmentName") ?? - throw new ArgumentNullException("FabApprovalEnvironmentName environment variable not found"); + if (!Boolean.TryParse(Environment.GetEnvironmentVariable("FabApprovalShouldSendEmail"), out _shouldSendEmail)) + throw new ArgumentNullException("FabApprovalShouldSendEmail environment variable not found"); } public async Task SendEmail(IEnumerable recipients, @@ -40,7 +40,7 @@ public class SmtpService : ISmtpService { bool messageWasSent = false; try { - if (!_environmentName.ToLower().Equals("development")) { + if (_shouldSendEmail) { int remainingRetries = maxRetries; while (!messageWasSent && remainingRetries > 0) { try {