E-mail küldése 10 próbálkozásra, 2 mp-es várakozással
This commit is contained in:
@@ -285,7 +285,7 @@ namespace WorkFlowCheck.BL.Services
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Log.Error(ex.Message);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,11 +51,43 @@ namespace WorkFlowCheck.BL.Services
|
||||
}
|
||||
|
||||
message.Body = builder.ToMessageBody();
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user