我有以下发送电子邮件的脚本。当我使用命令
在普通cmd窗口上运行此脚本时EmailTo.vbs "email" "Subject" "msgBody"
我收到收件箱中的电子邮件,但当我在管理员命令窗口中运行时,我收到错误: 错误:无法创建名为“Outllok.Application”的对象 代码:8008005 来源:WScript.CreateObject
对于Automation,我需要在admin命令模式下运行此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 :(得分:0)
我认为您在创建邮件时可能需要延迟绑定:
Set newMail = ol.CreateItem(0)
olMailItem
枚举为0