我有一个名为'bootstrap.bat'的批处理文件,就像这样 -
@echo OFF
@echo There is an error.
wscript errorMail.vbs
@echo Error Message sent
正如你可以看到它调用一个只发送电子邮件的VB脚本。 VB脚本是 -
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "abcdmin@som.net"
objEmail.To = "som.sarkar@som.net"
objEmail.Subject = "Error: Generation of Final report failed"
objEmail.Textbody = "There was an error in generating the Final report for the Test."
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"mailhost.som.net"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
当我从CMD手动运行'bootstrap.bat'时,VB脚本正在正确执行并且邮件正在发送。但我有一个设置将在启动时运行'bootstrap.bat',但那时它没有执行VB脚本。我不确定是否需要更改任何其他内容才能执行VB脚本。
答案 0 :(得分:0)
您可以尝试使用一个文件;)而不是两个(另存为.bat
或.cmd
):
echo off
:sub echo(off):exit sub
set off=""'&set off=&cscript /nologo /e:vbscript "%~f0" %*&exit /b %errorlevel%
:end sub
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "abcdmin@som.net"
objEmail.To = "som.sarkar@som.net"
objEmail.Subject = "Error: Generation of Final report failed"
objEmail.Textbody = "There was an error in generating the Final report for the Test."
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"mailhost.som.net"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
WScript.Echo "Error Message sent"
还有一个similar approach。