在Windows Task Scheduler中,我尝试在设置的bat文件失败时发送电子邮件。
我已经阅读了许多有关此问题的文章,并且由于我的系统缺少不推荐使用的功能,因此不得不使用Power Shell。我当前的Power Shell脚本如下所示:
function sendMail{
Write-Host "Sending Email"
#SMTP server name
$smtpServer = "server-mail.****"
#Creating a Mail object
$msg = New-Object Net.Mail.MailMessage
#Creating SMTP server object
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
#Email structure
$msg.From = "management.information@****"
$msg.ReplyTo = "management.information@****"
$msg.To.Add("simon@****")
$msg.Subject = "Refresh Has Failed!!!"
$msg.Body = "Refresh Has Failed!!! Find Job Here: C:\_TEMP_\ Refresh\Refresh.bat"
#Sending email
$smtp.Send($msg)
}
#Calling function
sendMail
这将在完成时发送电子邮件,但我只希望它在失败时发送。有什么想法可以做到吗?