List := FQueue.LockList;
for I := 0 to List.Count - 1 do
begin
Mail := TIdMessageTaskman(List[I]);
FEventLogger.LogMessage( 'Mail' + Mail.ToString, EVENTLOG_INFORMATION_TYPE , 0, 2);
try
try
FidSmtp.Connect();
FidSmtp.Send(Mail);
except
on e: exception do
begin
FEventLogger.LogMessage('Error sending mail ' + e.ClassName + ', ' +
e.Message, EVENTLOG_ERROR_TYPE, 0, 2);
MarkMailExecution(Mail.TaskID, Mail.NotificationID, False, e.Message);
Continue;
end;
end;
finally
begin
if FidSmtp.Connected then
FidSmtp.Disconnect;
end;
end;
FEventLogger.LogMessage( 'after finally', EVENTLOG_INFORMATION_TYPE , 0, 2);
MarkMailExecution(Mail.TaskID, Mail.NotificationID, True, '');
FreeAndNil(Mail)
因此,下面的代碼有效,但一旦發送電子郵件出現問題並引發異常,服務就會停止。我有辦法讓它繼續並通過所有隊列嗎?即使有錯誤的消息。例如,當我「附加」一個不存在的文件時,會停止我的服務的錯誤。嘗試除停止服務執行
你爲什麼要吞食所有的異常? –
@DavidHeffernan不確定你的意思。 – CiucaS
https://en.m.wikipedia.org/wiki/Error_hiding –