2011-07-29 10 views
0

基本的に私に電子メールを送信するWindows 2003サーバーで実行される単純なスクリプトを探しています。私はWindowsサービスの自動回復マネージャーを使ってスクリプトを起動する予定です。Windowsプログラミング - メールスクリプトを送信

私は、このスクリプトの使用をトリガすることができる方法を参照する見つけた:How to monitor Windows services

をしかし、私は、Windowsプラットフォームのために働くだろうメールを送るスクリプトを書く上でいくつかの助けを必要としています。私はどの言語がこれに最も適しているかはわかりません。ありがとう。

+0

... http://superuser.com/questions/316896/monitoring-script-for-window-services – Buggabill

+0

PowerShell? Net.Mail.SmtpClientはメールを送信できます。 – Fozi

答えて

1

簡単な方法の1つは、javascript(またはVBscript)を使用することです。あなたが "Server.CreateObject(" CDO.Message ")のためにGoogleの場合は、より多くの例を見つけるでしょう。

以下のコードを拡張子 ".js"のファイルに入れてください(例:email.js )。コマンドラインで "cscript email.js"を使用して呼び出します。サーバー名と電子メールを有効な値に置き換えます。

Windows 2003にはCDOがインストールされている必要があります。スクリプトはWindows XPとWindows 2003で動作していました。この例ではネットワーク経由でsmtpサーバーを使用していますが、その他のオプションもあります。

Powershellはおそらくサーバー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;
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');興味深い

関連する問題