mail sending retries
I am testing that when sending an email fails, I try to resend another one with a maximum of 5 attempts. For this I have the following function:
function envio_mail($emailDatos) {
for ($nintento = 0; $nintento -lt 5; $nintento++) {
try {
Send-MailMessage u/emailDatos -ErrorAction Stop -Encoding utf8
Write-Output "$(Get-Date)`tOK`tEmail enviado"
break
} catch {
Write-Output "$(Get-Date)`tERROR`tNo se puede enviar el correo. Reintento: $($nintento)"
Start-Sleep 10
}
}
}
What would be the correct way to do this?