E-mail küldése 10 próbálkozásra, 2 mp-es várakozással

This commit is contained in:
2026-01-21 09:19:22 +01:00
parent 4f4ca5cec4
commit 41542e492d
2 changed files with 38 additions and 6 deletions
@@ -285,7 +285,7 @@ namespace WorkFlowCheck.BL.Services
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
}
@@ -51,12 +51,44 @@ namespace WorkFlowCheck.BL.Services
}
message.Body = builder.ToMessageBody();
const int maxRetries = 10;
const int delayMs = 2000;
bool authenticated = false;
Exception lastException = null;
for (int attempt = 1; attempt <= maxRetries; attempt++)
{
try
{
using var smtp = new SmtpClient();
await smtp.ConnectAsync(_settings.SmtpServer, _settings.SmtpPort, SecureSocketOptions.StartTls);
await smtp.AuthenticateAsync(_settings.Username, _settings.Password);
await smtp.SendAsync(message);
await smtp.DisconnectAsync(true);
authenticated = true;
break; // 🎯 siker
}
catch (Exception ex)
{
lastException = ex;
Log.ForContext("TAG", "BusinessFlow").Error(lastException?.Message ?? "E-mail küldése sikertelen!");
if (attempt == maxRetries)
break;
// ⏳ várunk 1 másodpercet és újrapróbáljuk
await Task.Delay(delayMs);
}
}
if (!authenticated)
{
// 🔴 IDE ÍRHATSZ MAJD SAJÁT LOGIKÁT
Log.ForContext("TAG", "BusinessFlow").Error(lastException?.Message ?? "E-mail küldése sikertelen!");
}
return true;
}
public async Task<bool> SendFCMTokenAsync(string token)