【发布时间】:2017-04-09 17:15:06
【问题描述】:
我有以下用于发送电子邮件的脚本。当我使用命令在 普通 cmd 窗口 上运行此脚本时
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
【问题讨论】:
-
用
CreateObject试试看,不要在前面加WScript
标签: vba command-line vbscript outlook admin