寻找一个可以在Windows 2003服务器上运行的简单脚本,该脚本基本上会向我发送电子邮件。我打算用Windows服务自动恢复管理器来触发脚本。
我确实找到了如何触发使用此脚本的参考:How to monitor Windows services
但是我需要一些帮助来编写适用于Windows平台的发送电子邮件脚本。我不确定哪种语言最适合这个。感谢。
答案 0 :(得分:1)
一种简单的方法是使用javascript(或VBscript)。如果你谷歌搜索“Server.CreateObject(”CDO.Message“)”,你会发现更多的例子。
将下面的代码放在扩展名为“.js”的文件中,例如email.js 要在命令行上调用“cscript email.js”。用有效值替换服务器名称和电子邮件。
Windows 2003应安装CDO。该脚本曾用于Windows XP和Server 2003.此示例使用网络上的smtp服务器,但也有其他选项。
Powershell可能适用于服务器2003 ..因此它可能是另一种选择。 ============================== code =================== ===========
function sendMail(strFrom,strTo,strSubject,strMessage){
试试{
objMail = Server.CreateObject(“CDO.Message”);
objConfig = Server.CreateObject(“CDO.Configuration”);
objFields = objConfig.Fields;
with (objFields) {
项目(“http://schemas.microsoft.com/cdo/configuration/sendusing”)= 2;
项目(“http://schemas.microsoft.com/cdo/configuration/smtpserver”)=“xxxxsmtp.xxxserver.xxorg”;
项目(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”)= 25;
项目(“http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout”)= 30;
更新();
}
用(objMail){
Configuration = objConfig;
To = strTo; //“\”User \“,”\“AnotherUser \”;“
From = strFrom;
Subject = strSubject;
TextBody = strMessage;
//如果我们需要发送一个附件
//AddAttachment("D:\\test.doc");
Send();
}
}
catch(e) {
WScript.Echo(e.message);
return false;
}
delete objFields;
delete objConfig;
delete objMail;
return true;
}
// WScript.Echo( 'QQQ');
sendMail('from @xxxxxx.com','to @yyy.com','test','msg');