如何让此脚本加载HTML文件的内容并将其作为电子邮件正文发送。
我一直收到错误消息
第8行
无效的过程调用或参数
代码:800A0005
我试过了,感谢你。
但是当它读取htm文件时脚本会中断,因为文件中有多个“。
我收到此错误
Line: 13
Object doesn't support this property or method: 'objEmail.CreateMHTMLBody'
code: 800A01B6
我该怎么做才能解决它。
Dim fso
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "user@Example.com"
objEmail.Subject = "Test Email"
Const ForReading=1
Set fso = CreateObject("Scripting.FileSystemObject")
Set dict = CreateObject("Scripting.Dictionary")
BodyText = fso.OpenTextFile("C:\Users\user\Desktop\Email.htm",ForReading).ReadAll
objEmail.CreateMHTMLBody = BodyText
objEmail.AddAttachment "C:\Users\user\Desktop\test.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set dict = CreateObject("Scripting.Dictionary")
Set file = fso.OpenTextFile ("C:\Users\user\Desktop\address.txt", 1)
row = 0
Do Until file.AtEndOfStream
line = file.Readline
dict.Add row, line
row = row + 1
objEmail.To = line
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"127.0.0.1"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
Loop
答案 0 :(得分:1)
Set
语句将对象引用分配给变量或属性; ReadAll
方法读取整个 TextStream 文件并返回结果字符串。 因此,下一个代码段应该可以工作:
Const ForReading=1
Set fso = CreateObject("Scripting.FileSystemObject")
Set dict = CreateObject("Scripting.Dictionary")
BodyText = fso.OpenTextFile("C:\Users\user\Desktop\Email.htm",ForReading).ReadAll
' superabundant Set fso = CreateObject("Scripting.FileSystemObject")
' superabundant Set dict = CreateObject("Scripting.Dictionary")
Set file = fso.OpenTextFile ("C:\Users\user\Desktop\address.txt", 1)
' …
'
objEmail.Subject = "Test Email"
objEmail.HtmlBody = BodyText
'…
请阅读Paul R. Sadowski的文章VBScript To Send Email Using CDO。提示如何使用CreateMHTMLBody
method从您计算机上的文件发送网页,而不是设置HTMLBody
属性。
答案 1 :(得分:0)
您正在使用FSO创建它。还有其他问题。您可以查看此very similar question以了解如何使用FSO。