0
以下是我的VBScript代码,用于发送带有附加文件的电子邮件。该文件存在于我发送电子邮件时需要抓取的位置。从命令行传递文件位置
Set objMessage = CreateObject("CDO.Message")
Set args = WScript.Arguments
Set arg1 = args.Item(0)
objMessage.Subject = "Sample subject"
objMessage.From = "[email protected]"
objMessage.To = "[email protected]"
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 runtime error: Object required: '[string: "D:\Users\me\Desk"]'
任何建议可能是什么问题呢?
你应该可以使用'objMessage.AddAttachment args(0)' – Squashman
我试过你说的,但它给了我相同的确切的错误。 – JohnG
这很奇怪。这就是我用vbscript完成所有电子邮件的方式。我使用了一个通用的vbscript,我把所有的东西都作为参数传递给它。 – Squashman