开发者

Windows programming - send email script

开发者 https://www.devze.com 2023-03-24 02:55 出处:网络
Looking for a simple script that would run on windows 2003 server that would basic开发者_开发技巧ally send me an email. What I plan to do us the windows services auto recovery manager to trigger the s

Looking for a simple script that would run on windows 2003 server that would basic开发者_开发技巧ally send me an email. What I plan to do us the windows services auto recovery manager to trigger the script.

I did find a reference to how I can trigger the use of this script: How to monitor Windows services

But I need some help on writing an send email script that would work for windows platform. I'm not sure what language would be best for this. thanks.


One simple way would be to use javascript (or VBscript). If you google for "Server.CreateObject("CDO.Message")" you will find more examples.

Put the code below in a file with extension: ".js", for example email.js To call use "cscript email.js" on the command line. Replace server name and emails with valid values.

Windows 2003 should have CDO installed. The script used to work on windows XP and server 2003. This example uses smtp server over the network but there are other options too.

Powershell is probably available for server 2003 .. so it could be another option. ============================== code ==============================

function sendMail ( strFrom, strTo, strSubject, strMessage ) { try {
objMail = Server.CreateObject("CDO.Message"); objConfig = Server.CreateObject("CDO.Configuration"); objFields = objConfig.Fields;

    with (objFields) {          

Item("http://schemas.microsoft.com/cdo/configuration/sendusing")= 2;
Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")= "xxxxsmtp.xxxserver.xxorg";
Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")= 25;
Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30;
Update(); }
with (objMail) {
Configuration = objConfig; To = strTo; //"\"User\" ,"\"AnotherUser\" ;" From = strFrom; Subject = strSubject; TextBody = strMessage; //if we need to send an attachement

    //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');

0

精彩评论

暂无评论...
验证码 换一张
取 消