【发布时间】:2016-08-19 18:02:34
【问题描述】:
下面是我的 VBScript 代码,用于发送附有文件的电子邮件。该文件位于我发送电子邮件时需要抓取的位置。
Set objMessage = CreateObject("CDO.Message")
Set args = WScript.Arguments
Set arg1 = args.Item(0)
objMessage.Subject = "Sample subject"
objMessage.From = "test@gmail.com"
objMessage.To = "test2@gmail.com"
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 运行时错误:需要对象:'[string: "D:\Users\me\Desk"]'
有什么建议吗?
【问题讨论】:
-
你应该可以只使用
objMessage.AddAttachment args(0) -
我试过你说的,但它给了我同样的错误。
-
这很奇怪。这就是我使用 vbscript 处理所有电子邮件的方式。我使用了一个通用的 vbscript,我将所有内容都作为参数传递给它。
标签: command-line vbscript arguments email-attachments