2016-11-25 42 views
0

私は電子メールを送信するための次のスクリプトがあります。私は、コマンドVBSで "Outlook.Application" 8008005という名前のオブジェクトを作成できませんでした

EmailTo.vbs "email" "Subject" "msgBody" 

通常のCMDウィンドウ上でこのスクリプトを実行すると、私は私の受信トレイにメールを取得するが、私は管理者コマンドウィンドウでこれを実行するとはその後、私はエラーを取得: エラー:作成できませんでしたオブジェクト "Outllok.Application" コード:8008005 ソース:WScript.CreateObject

自動化では、このvbsを管理コマンドモードで実行する必要があります。管理モードでは実行されません。

私はあなたのメールアイテムを作成するときに遅延バインディングに必要かもしれないと思う
Dim ToAddress 
Dim MessageSubject 
Dim MessageBody 
Dim MessageAttachment 
addAttachment = 0 

Dim ol, ns, newMail 


ToAddress = Wscript.Arguments(0) 
MessageSubject = Wscript.Arguments(1) 
MessageBody = Wscript.Arguments(2) 

if Wscript.Arguments.Count > 3 Then 
addAttachment=1 
MessageAttachment = Wscript.Arguments(3) 
End If 

' connect to Outlook 
Set ol = WScript.CreateObject("Outlook.Application") 
Set ns = ol.getNamespace("MAPI") 

Set newMail = ol.CreateItem(olMailItem) 
newMail.Subject = MessageSubject 
newMail.Body = MessageBody & vbCrLf 

' validate the recipient, just in case... 
Set myRecipient = ns.CreateRecipient(ToAddress) 
myRecipient.Resolve 
If Not myRecipient.Resolved Then 
    MsgBox "Unknown recipient" 
Else 
    newMail.Recipients.Add(ToAddress) 
    if addAttachment = 1 Then newMail.Attachments.Add(MessageAttachment).Displayname = "Check this out" End If 
    newMail.Send 
End If 

Set ol = Nothing 
+0

に列挙し、それの前に 'WScript'を追加することなく、' CreateObject'でそれを試してみてください – Dave

答えて

0

Set newMail = ol.CreateItem(0) 

olMailItem0

関連する問題