Hi all,
I encountered the same problem. I need to handle errors generated during sending an email.
How could be possible to catch such error (if ‘on-error’ is not the right solution)?
(My goal is detect error during sending an email and try to resend it again in that case.)
Set in the on-error section global variable to send result. In the scheduled script resend e-mail if it is needed.
You could also use this variable as condition in the :do { } while=( ); to effectively send the e-mail.
Thanks for fast reply.
I’m not sure if I understand what you mean.
How could I fill global variable with result of sending an email (whether email was sent successfully or not)?
If I try:
:global RES
:set RES [/tool e-mail send to="..." body="..." subject="..."]
Thanks.
I tried something like this already, but it doesn’t work. Like Martins S. wrote for 23q above: E-mail tool itself does not return error in CLI and works in background. On-error is not solution for e-mail tool.
Even though, I tried your suggestion like this:
{
:local RES 1;
:do {
:do {
:log info "Sending an email...";
/tool e-mail send ... ;
:log info "Email sent.";
} on-error={
:log info "!Error sending an e-mail";
:set RES 0;
}
} while (RES = 0)
:log info "Over.";
}
And here is output in log:
Is there any other way how could email errors be handled?
One more option to check if there was problems with sending email is to check “last-status” value. I sometimes use it in scripts to check if last attempt to send email was successful or not.
Thank you very much… this is pretty close to the goal!
I suggest it will work great in most of the common cases. But I think it will fail on some special cases.
I made script like this:
:local attempts 0;
do {
:set attempts ($attempts+1);
:if ($attempts > 1) do {:log info ("ERROR - last email status: ".[/tool e-mail get last-status];); :delay 2s;}
/tool e-mail send ... ;
do {:delay 200ms;} while ([/tool e-mail get last-status] = "in-progress")
} while ($attempts < 5 and [/tool e-mail get last-status] != "succeeded")
=> script tries to resend email every 2 seconds, if last status was not “succeeded”.
But let’s suppose there is one email sending in progress with large attachment, so it takes a lot of time to send it (last-status is ‘in-progress’). Now let’s suppose, that another short email is sent while the first one is still in progress. If 2nd email is sent with success, last-status will be updated to ‘succeeded’ and that will terminate first script - so it will not check if first email was sent with success or failure. And if first email crashes with error, first email will not be resent again.
Is that right?