Don't send emails in dev
This commit is contained in:
parent
a86fbbbea0
commit
fd23214ef7
@ -13,12 +13,15 @@ public interface ISmtpService {
|
||||
public class SmtpService : ISmtpService {
|
||||
private ILogger<SmtpService> _logger;
|
||||
private ISmtpClientWrapper _smtpClient;
|
||||
private string _environmentName;
|
||||
|
||||
public SmtpService(ILogger<SmtpService> 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");
|
||||
}
|
||||
|
||||
public async Task<bool> SendEmail(IEnumerable<MailAddress> recipients,
|
||||
@ -37,6 +40,7 @@ public class SmtpService : ISmtpService {
|
||||
bool messageWasSent = false;
|
||||
|
||||
try {
|
||||
if (!_environmentName.ToLower().Equals("development")) {
|
||||
int remainingRetries = maxRetries;
|
||||
while (!messageWasSent && remainingRetries > 0) {
|
||||
try {
|
||||
@ -61,6 +65,9 @@ public class SmtpService : ISmtpService {
|
||||
_logger.LogError($"Message not sent successfully. Exception: {ex.Message}");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
messageWasSent = true;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"An exception occurred when attempting to send notification. Exception: {ex.Message}");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user