0

寻找一个可以在 Windows 2003 服务器上运行的简单脚本,它基本上会向我发送一封电子邮件。我打算用 Windows 服务自动恢复管理器来触发脚本。

我确实找到了有关如何触发使用此脚本的参考:如何监视 Windows 服务

但我需要一些帮助来编写适用于 Windows 平台的发送电子邮件脚本。我不确定哪种语言最适合这个。谢谢。

4

1 回答 1

1

一种简单的方法是使用 javascript(或 VBscript)。如果您在 Google 上搜索“Server.CreateObject("CDO.Message")”,您会发现更多示例。

将下面的代码放在一个扩展名为“.js”的文件中,例如 email.js 在命令行中调用使用“cscript email.js”。用有效值替换服务器名称和电子邮件。

Windows 2003 应该安装了 CDO。该脚本用于在 windows XP 和 server 2003 上运行。此示例通过网络使用 smtp 服务器,但也有其他选项。

Powershell 可能适用于 server 2003 .. 所以它可能是另一种选择。============================== 代码=================== ===========

函数 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;
更新(); }
with (objMail) {
配置 = 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');

于 2011-07-30T01:11:04.450 回答