2016-11-25 73 views
0

我有用于发送电子邮件的以下脚本。当我用命令的正常cmd窗口运行此脚本无法在VBS中创建名为“Outlook.Application”8008005的对象

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

我得到了我的收件箱中的电子邮件,但当我在管理员命令窗口中运行这个然后我得到错误: 错误:无法创建命名对象“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

用'CreateObject'尝试没有在它的前面加上'WScript' – Dave

回答

0

我想创建邮件项目时,您可能需要后期绑定:

Set newMail = ol.CreateItem(0) 

olMailItem列举到0