尋找一個簡單的腳本,將運行在Windows 2003服務器,基本上會給我一個電子郵件。我打算讓我們的Windows服務自動恢復管理器來觸發腳本。Windows編程 - 發送電子郵件腳本
我沒有找到我怎麼能觸發使用這個腳本的參考:How to monitor Windows services
但我需要寫一個發送電子郵件腳本,將適用於Windows平臺的工作有所幫助。我不確定哪種語言對此最好。謝謝。
尋找一個簡單的腳本,將運行在Windows 2003服務器,基本上會給我一個電子郵件。我打算讓我們的Windows服務自動恢復管理器來觸發腳本。Windows編程 - 發送電子郵件腳本
我沒有找到我怎麼能觸發使用這個腳本的參考:How to monitor Windows services
但我需要寫一個發送電子郵件腳本,將適用於Windows平臺的工作有所幫助。我不確定哪種語言對此最好。謝謝。
一個簡單的方法是使用javascript(或VBscript)。如果你是谷歌的「Server.CreateObject(」CDO.Message「)」你會發現更多的例子。
將以下代碼放入擴展名爲「.js」的文件中,例如email.js 在命令行中調用「cscript email.js」。用有效值替換服務器名稱和電子郵件。
Windows 2003應該安裝CDO。該腳本用於在Windows XP和Server 2003上工作。本示例通過網絡使用smtp服務器,但也有其他選項。
Powershell可能適用於服務器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(); }
with(objMail){
Configuration = objConfig; To = strTo; // 「\」 用戶\ 「 」\「 AnotherUser \」;」 從= strFrom; 主題= 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的( '[email protected]', '[email protected]', '測試', 'MSG');
有趣... http://superuser.com/questions/316896/monitoring-script-for-window-services – Buggabill
PowerShell? Net.Mail.SmtpClient可以發送郵件。 – Fozi