编辑电子邮件脚本以从文件中读取地址

时间:2016-04-08 13:19:26

标签: email vbscript

如何让脚本从文本文件中一次加载一个电子邮件地址,而不是手动输入电子邮件?

我一直收到错误消息

  

第6行   需要的对象:“
  代码800A01A8

我做错了什么?

Dim fso

Set objEmail = CreateObject("CDO.Message")
objEmail.From = "admin1@fabrikam.com"
Set dict = CreateObject("Scripting.Dictionary")
Set file = fso.OpenTextFile ("C:\e.txt", 1)
row = 0
Do Until file.AtEndOfStream
  line = file.Readline
  dict.Add row, line
  row = row + 1
  objEmail.To = file
  objEmail.Subject = "Test Email 2"
  objEmail.Textbody = "This Is A Test Message"
  objEmail.AddAttachment "C:\test.txt"
  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

1 个答案:

答案 0 :(得分:0)

在第6行:

Set file = fso.OpenTextFile ("C:\e.txt", 1)

fso为空/未定义。你需要一个

Set fso = CreateObject("Scripting.FileSystemObject")

之前。

你的

objEmail.To = file

可能应该是

objEmail.To = line