How to re-run one line of a PowerShell cmdlet if it fails
- by pansal
I wrote a PowerShell script which is supposed to send emails automatically, but sometimes the email won't send out due to a network issue.
Here is how I'm sending email:
$smtp_notification.Send($mail_notification)
Here are the error logs:
Exception calling "Send" with "1" argument(s): "Failure sending mail."
At line:1 char:24
+ $smtp_notification.Send <<<< ($mail_notification)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Is there anyway to re-run the sending line when I met this failure? Can anyone give me some suggestions please?