簡體   English   中英

Windows編程-發送電子郵件腳本

[英]Windows programming - send email script

尋找一個可以在Windows 2003 Server上運行的簡單腳本,該腳本基本上會向我發送電子郵件。 我計划為我們執行Windows Services自動恢復管理器來觸發腳本。

我確實找到了有關如何觸發此腳本使用的參考: 如何監視Windows服務

但是在編寫適用於Windows平台的發送電子郵件腳本時,我需要一些幫助。 我不確定哪種語言最適合。 謝謝。

一種簡單的方法是使用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) {          

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(); }
與(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');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM