2016-08-19 9 views
0

以下は、ファイルが添付された電子メールを送信する私のVBScriptコードです。このファイルは、電子メールを送信するときに取得する必要がある場所に存在します。私が使用して、コマンドラインからこのスクリプトを実行するにはコマンドラインからファイルの場所を渡す

Set objMessage = CreateObject("CDO.Message") 
Set args = WScript.Arguments 
Set arg1 = args.Item(0) 
objMessage.Subject = "Sample subject" 
objMessage.From = "[email protected]" 
objMessage.To = "[email protected]" 
objMessage.TextBody = "Please see the error logs attached with this email" 
objMessage.AddAttachment ""&arg1&"" 
'==This section provides the configuration information for the remote SMTP server. 
'==Normally you will only change the server name or IP. 
objMessage.Configuration.Fields.Item _ 
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 

'Name or IP of Remote SMTP Server 
objMessage.Configuration.Fields.Item _ 
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "hostname" 

'Server port (typically 25) 
objMessage.Configuration.Fields.Item _ 
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 

objMessage.Configuration.Fields.Update 

'==End remote SMTP server configuration section== 

objMessage.Send 

>cscript sendemail.vbs D:\users\me\Desktop\readme.txt 

私はこれを実行すると、私は言ってエラーを取得:

D:\Users\me\Desktop\sendemail.vbs(3, 1) Microsoft VBScript runtime error: Object required: '[string: "D:\Users\me\Desk"]'

任意の提案はこれで間違って何ができますか?

+0

'objMessage.AddAttachment args(0)' – Squashman

+0

私はあなたが言ったことを試しましたが、それは私に同じ正確なエラーを与えます。 – JohnG

+0

が奇妙です。それは私がvbscriptですべての電子メールをやりとりする方法です。私はそれに引数としてすべてを渡す一般的なvbscriptを使用します。 – Squashman

答えて

1

エラーメッセージに実際にすべてが表示されます。 Argumentsコレクションはオブジェクトですが、最初の要素はオブジェクトではありません。 VBScriptではプリミティブなデータ型の文字列です。 Setキーワードは、オブジェクトを変数に割り当てるためのものです。プリミティブデータ型は、代入演算子を使用するだけで割り当てられます。この中

Set arg1 = args.Item(0) 

arg1 = args.Item(0) 

とエラーが表示されなくなります。この

変更。

関連する問題